+2003-11-02 Hrvoje Niksic <hniksic@xemacs.org>
+
+ * wget.h: Retired the `boolean' type. Moved the DEFAULT_LOGFILE
+ define to log.h. Moved the INFINITE_RECURSION define to recur.h.
+
+ * xmalloc.h: Renamed FREE_MAYBE to xfree_null and moved the
+ definition from wget.h to xmalloc.h.
+
2003-11-02 Hrvoje Niksic <hniksic@xemacs.org>
* html-parse.c (decode_entity): New function; split the decoding
/* Construct the backup filename as the original name plus ".orig". */
size_t filename_len = strlen(file);
char* filename_plus_orig_suffix;
- boolean already_wrote_backup_file = FALSE;
+ int already_wrote_backup_file = 0;
slist* converted_file_ptr;
static slist* converted_files = NULL;
while (converted_file_ptr != NULL)
if (strcmp(converted_file_ptr->string, file) == 0)
{
- already_wrote_backup_file = TRUE;
+ already_wrote_backup_file = 1;
break;
}
else
static void
delete_cookie (struct cookie *cookie)
{
- FREE_MAYBE (cookie->domain);
- FREE_MAYBE (cookie->path);
- FREE_MAYBE (cookie->attr);
- FREE_MAYBE (cookie->value);
+ xfree_null (cookie->domain);
+ xfree_null (cookie->path);
+ xfree_null (cookie->attr);
+ xfree_null (cookie->value);
xfree (cookie);
}
\f
{
if (!VALUE_NON_EMPTY)
return 0;
- FREE_MAYBE (cookie->domain);
+ xfree_null (cookie->domain);
/* Strictly speaking, we should set cookie->domain_exact if the
domain doesn't begin with a dot. But many sites set the
domain to "foo.com" and expect "subhost.foo.com" to get the
{
if (!VALUE_NON_EMPTY)
return 0;
- FREE_MAYBE (cookie->path);
+ xfree_null (cookie->path);
cookie->path = strdupdelim (value_b, value_e);
return 1;
}
request = strtok (NULL, "\"");
/* Has the `pwd' been already allocated? Free! */
- FREE_MAYBE (*pwd);
+ xfree_null (*pwd);
*pwd = xstrdup (request);
if (error || ignore)
{
DEBUGP (("Skipping.\n"));
- FREE_MAYBE (cur.name);
- FREE_MAYBE (cur.linkto);
+ xfree_null (cur.name);
+ xfree_null (cur.linkto);
xfree (line);
continue;
}
switch (system_type)
{
case ST_UNIX:
- return ftp_parse_unix_ls (file, FALSE);
+ return ftp_parse_unix_ls (file, 0);
case ST_WINNT:
{
/* Detect whether the listing is simulating the UNIX format */
if (c >= '0' && c <='9')
return ftp_parse_winnt_ls (file);
else
- return ftp_parse_unix_ls (file, TRUE);
+ return ftp_parse_unix_ls (file, 1);
}
case ST_VMS:
return ftp_parse_vms_ls (file);
case ST_MACOS:
- return ftp_parse_unix_ls (file, TRUE);
+ return ftp_parse_unix_ls (file, 1);
default:
logprintf (LOG_NOTQUIET, _("\
Unsupported listing type, trying Unix listing parser.\n"));
- return ftp_parse_unix_ls (file, FALSE);
+ return ftp_parse_unix_ls (file, 0);
}
}
\f
+ (tmpp ? (1 + strlen (tmpp)) : 0) + 2);
sprintf (upwd, "%s%s%s@", tmpu, tmpp ? ":" : "", tmpp ? tmpp : "");
xfree (tmpu);
- FREE_MAYBE (tmpp);
+ xfree_null (tmpp);
}
else
upwd = xstrdup ("");
#include "host.h"
#include "netrc.h"
#include "convert.h" /* for downloaded_file */
+#include "recur.h" /* for INFINITE_RECURSION */
#ifndef errno
extern int errno;
break;
case FTPSRVERR :
/* PWD unsupported -- assume "/". */
- FREE_MAYBE (con->id);
+ xfree_null (con->id);
con->id = xstrdup ("/");
break;
case FTPOK:
/* If a connection was left, quench it. */
if (rbuf_initialized_p (&con.rbuf))
CLOSE (RBUF_FD (&con.rbuf));
- FREE_MAYBE (con.id);
+ xfree_null (con.id);
con.id = NULL;
- FREE_MAYBE (con.target);
+ xfree_null (con.target);
con.target = NULL;
return res;
}
struct fileinfo *next = f->next;
xfree (f->name);
- FREE_MAYBE (f->linkto);
+ xfree_null (f->linkto);
xfree (f);
if (next)
if (meta_disallow_follow)
*meta_disallow_follow = ctx.nofollow;
- FREE_MAYBE (ctx.base);
+ xfree_null (ctx.base);
read_file_free (fm);
return ctx.head;
}
void
cleanup_html_url (void)
{
- FREE_MAYBE (interesting_tags);
- FREE_MAYBE (interesting_attributes);
+ xfree_null (interesting_tags);
+ xfree_null (interesting_attributes);
}
static void
free_hstat (struct http_stat *hs)
{
- FREE_MAYBE (hs->newloc);
- FREE_MAYBE (hs->remote_time);
- FREE_MAYBE (hs->error);
+ xfree_null (hs->newloc);
+ xfree_null (hs->remote_time);
+ xfree_null (hs->error);
/* Guard against being called twice. */
hs->newloc = NULL;
DEBUGP (("---request begin---\n%s", request));
/* Free the temporary memory. */
- FREE_MAYBE (wwwauth);
- FREE_MAYBE (proxyauth);
- FREE_MAYBE (cookies);
+ xfree_null (wwwauth);
+ xfree_null (proxyauth);
+ xfree_null (cookies);
xfree (full_path);
/* Send the request to server. */
logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("End of file while parsing headers.\n"));
xfree (hdr);
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock);
return HEOF;
}
logprintf (LOG_NOTQUIET, _("Read error (%s) in headers.\n"),
strerror (errno));
xfree (hdr);
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock);
return HERR;
}
&& authenticate_h)
{
/* Authorization is required. */
- FREE_MAYBE (type);
+ xfree_null (type);
type = NULL;
free_hstat (hs);
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
hs->newloc ? _(" [following]") : "");
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
might be more bytes in the body. */
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
return NEWLOCATION;
}
}
hs->res = 0;
/* Mark as successfully retrieved. */
*dt |= RETROKF;
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
might be more bytes in the body. */
return RETRUNNEEDED;
\n\
Continued download failed on this file, which conflicts with `-c'.\n\
Refusing to truncate existing file `%s'.\n\n"), *hs->local_file);
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock);
return CONTNOTSUPPORTED;
}
{
/* This means the whole request was somehow misunderstood by the
server. Bail out. */
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock);
return RANGEERR;
}
logputs (LOG_VERBOSE, "\n");
}
}
- FREE_MAYBE (type);
+ xfree_null (type);
type = NULL; /* We don't need it any more. */
/* Return if we have no intention of further downloading. */
/* In case the caller cares to look... */
hs->len = 0L;
hs->res = 0;
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
might be more bytes in the body. */
return RETRFINISHED;
logprintf (LOG_NOTQUIET, "%s: %s\n", *hs->local_file, strerror (errno));
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
might be more bytes in the body. */
- FREE_MAYBE (all_headers);
+ xfree_null (all_headers);
return FOPENERR;
}
}
if (flush_res == EOF)
hs->res = -2;
}
- FREE_MAYBE (all_headers);
+ xfree_null (all_headers);
if (hs->res == -2)
return FWRITEERR;
return RETRFINISHED;
if (has_html_suffix_p (*hstat.local_file))
*dt |= TEXTHTML;
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
use_ts = 0;
if (opt.timestamping)
{
- boolean local_dot_orig_file_exists = FALSE;
+ int local_dot_orig_file_exists = 0;
if (opt.backup_converted)
/* If -K is specified, we'll act on the assumption that it was specified
/* Try to stat() the .orig file. */
if (stat (filename_plus_orig_suffix, &st) == 0)
{
- local_dot_orig_file_exists = TRUE;
+ local_dot_orig_file_exists = 1;
local_filename = filename_plus_orig_suffix;
}
}
case SSLERRCTXCREATE: case CONTNOTSUPPORTED:
/* Fatal errors just return from the function. */
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return err;
break;
case FWRITEERR: case FOPENERR:
logprintf (LOG_NOTQUIET, _("Cannot write to `%s' (%s).\n"),
*hstat.local_file, strerror (errno));
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return err;
break;
case CONSSLERR:
logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return err;
break;
case NEWLOCATION:
_("ERROR: Redirection (%d) without location.\n"),
hstat.statcode);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return WRONGCODE;
}
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return NEWLOCATION;
break;
case RETRUNNEEDED:
/* The file was already fully retrieved. */
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
break;
case RETRFINISHED:
tms, hstat.statcode, hstat.error);
logputs (LOG_VERBOSE, "\n");
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return WRONGCODE;
}
Server file no newer than local file `%s' -- not retrieving.\n\n"),
local_filename);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
else if (tml >= tmr)
if (opt.spider)
{
logprintf (LOG_NOTQUIET, "%d %s\n\n", hstat.statcode, hstat.error);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
else if (hstat.res == 0) /* No read error */
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
else if (hstat.len < hstat.contlen) /* meaning we lost the
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
else /* the same, but not accepted */
;
if (!*ep)
return -1;
- FREE_MAYBE (*ret);
+ xfree_null (*ret);
*ret = strdupdelim (cp, ep);
return ep - au + 1;
}
options[i].variable);
if (skip < 0)
{
- FREE_MAYBE (realm);
- FREE_MAYBE (opaque);
- FREE_MAYBE (nonce);
+ xfree_null (realm);
+ xfree_null (opaque);
+ xfree_null (nonce);
return NULL;
}
else if (skip)
}
if (!realm || !nonce || !user || !passwd || !path || !method)
{
- FREE_MAYBE (realm);
- FREE_MAYBE (opaque);
- FREE_MAYBE (nonce);
+ xfree_null (realm);
+ xfree_null (opaque);
+ xfree_null (nonce);
return NULL;
}
#include "netrc.h"
#include "cookies.h" /* for cookie_jar_delete */
#include "progress.h"
+#include "recur.h" /* for INFINITE_RECURSION */
#ifndef errno
extern int errno;
file = (char *)xmalloc (strlen (home) + 1 + strlen (".wgetrc") + 1);
sprintf (file, "%s/.wgetrc", home);
}
- FREE_MAYBE (home);
+ xfree_null (home);
#else /* WINDOWS */
/* Under Windows, "home" is (for the purposes of this function) the
directory where `wget.exe' resides, and `wget.ini' will be used
{
char **pstring = (char **)closure;
- FREE_MAYBE (*pstring);
+ xfree_null (*pstring);
*pstring = xstrdup (val);
return 1;
}
{
char **pstring = (char **)closure;
- FREE_MAYBE (*pstring);
+ xfree_null (*pstring);
/* #### If VAL is empty, perhaps should set *CLOSURE to NULL. */
if (!*val)
{
/* Empty header means reset headers. */
- FREE_MAYBE (opt.user_header);
+ xfree_null (opt.user_header);
opt.user_header = NULL;
}
else
exec_name, com, val);
return 0;
}
- FREE_MAYBE (opt.progress_type);
+ xfree_null (opt.progress_type);
/* Don't call set_progress_implementation here. It will be called
in main() when it becomes clear what the log output is. */
extern acc_t *netrc_list;
free_netrc (netrc_list);
}
- FREE_MAYBE (opt.lfilename);
- FREE_MAYBE (opt.dir_prefix);
- FREE_MAYBE (opt.input_filename);
- FREE_MAYBE (opt.output_document);
+ xfree_null (opt.lfilename);
+ xfree_null (opt.dir_prefix);
+ xfree_null (opt.input_filename);
+ xfree_null (opt.output_document);
free_vec (opt.accepts);
free_vec (opt.rejects);
free_vec (opt.excludes);
free_vec (opt.domains);
free_vec (opt.follow_tags);
free_vec (opt.ignore_tags);
- FREE_MAYBE (opt.progress_type);
+ xfree_null (opt.progress_type);
xfree (opt.ftp_acc);
- FREE_MAYBE (opt.ftp_pass);
- FREE_MAYBE (opt.ftp_proxy);
- FREE_MAYBE (opt.https_proxy);
- FREE_MAYBE (opt.http_proxy);
+ xfree_null (opt.ftp_pass);
+ xfree_null (opt.ftp_proxy);
+ xfree_null (opt.https_proxy);
+ xfree_null (opt.http_proxy);
free_vec (opt.no_proxy);
- FREE_MAYBE (opt.useragent);
- FREE_MAYBE (opt.referer);
- FREE_MAYBE (opt.http_user);
- FREE_MAYBE (opt.http_passwd);
- FREE_MAYBE (opt.user_header);
+ xfree_null (opt.useragent);
+ xfree_null (opt.referer);
+ xfree_null (opt.http_user);
+ xfree_null (opt.http_passwd);
+ xfree_null (opt.user_header);
#ifdef HAVE_SSL
- FREE_MAYBE (opt.sslcertkey);
- FREE_MAYBE (opt.sslcertfile);
+ xfree_null (opt.sslcertkey);
+ xfree_null (opt.sslcertfile);
#endif /* HAVE_SSL */
- FREE_MAYBE (opt.bind_address);
- FREE_MAYBE (opt.cookies_input);
- FREE_MAYBE (opt.cookies_output);
+ xfree_null (opt.bind_address);
+ xfree_null (opt.cookies_input);
+ xfree_null (opt.cookies_output);
#endif
}
#ifndef LOG_H
#define LOG_H
+/* The log file to which Wget writes to after HUP. */
+#define DEFAULT_LOGFILE "wget-log"
+
/* Make gcc check for the format of logmsg() and debug_logmsg(). */
#ifdef __GNUC__
# define GCC_FORMAT_ATTR(a, b) __attribute__ ((format (printf, a, b)))
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
}
- FREE_MAYBE (redirected_URL);
- FREE_MAYBE (filename);
+ xfree_null (redirected_URL);
+ xfree_null (filename);
}
/* And then from the input file, if any. */
while (l)
{
t = l->next;
- FREE_MAYBE (l->acc);
- FREE_MAYBE (l->passwd);
- FREE_MAYBE (l->host);
+ xfree_null (l->acc);
+ xfree_null (l->passwd);
+ xfree_null (l->host);
xfree (l);
l = t;
}
int descend = 0;
char *url, *referer, *file = NULL;
int depth, html_allowed;
- boolean dash_p_leaf_HTML = FALSE;
+ int dash_p_leaf_HTML = 0;
if (opt.quota && total_downloaded_bytes > opt.quota)
break;
one, but we allow one more level so that the leaf
pages that contain frames can be loaded
correctly. */
- dash_p_leaf_HTML = TRUE;
+ dash_p_leaf_HTML = 1;
}
else
{
}
xfree (url);
- FREE_MAYBE (referer);
- FREE_MAYBE (file);
+ xfree_null (referer);
+ xfree_null (file);
}
/* If anything is left of the queue due to a premature exit, free it
(const char **)&d1, (const char **)&d2, &d3, &d4))
{
xfree (d1);
- FREE_MAYBE (d2);
+ xfree_null (d2);
}
}
url_queue_delete (queue);
#ifndef RECUR_H
#define RECUR_H
+/* For most options, 0 means no limits, but with -p in the picture,
+ that causes a problem on the maximum recursion depth variable. To
+ retain backwards compatibility we allow users to consider "0" to be
+ synonymous with "inf" for -l, but internally infinite recursion is
+ specified by -1 and 0 means to only retrieve the requisites of a
+ single document. */
+#define INFINITE_RECURSION -1
+
struct urlpos;
void recursive_cleanup PARAMS ((void));
int i;
for (i = 0; i < specs->count; i++)
xfree (specs->paths[i].path);
- FREE_MAYBE (specs->paths);
+ xfree_null (specs->paths);
xfree (specs);
}
\f
if (file)
*file = local_file ? local_file : NULL;
else
- FREE_MAYBE (local_file);
+ xfree_null (local_file);
url_free (u);
dt &= ~RETROKF;
}
- FREE_MAYBE (new_file);
- FREE_MAYBE (filename);
+ xfree_null (new_file);
+ xfree_null (filename);
}
/* Free the linked list of URL-s. */
struct urlpos *next = l->next;
if (l->url)
url_free (l->url);
- FREE_MAYBE (l->local_name);
+ xfree_null (l->local_name);
xfree (l);
l = next;
}
xfree (url->path);
xfree (url->url);
- FREE_MAYBE (url->params);
- FREE_MAYBE (url->query);
- FREE_MAYBE (url->fragment);
- FREE_MAYBE (url->user);
- FREE_MAYBE (url->passwd);
+ xfree_null (url->params);
+ xfree_null (url->query);
+ xfree_null (url->fragment);
+ xfree_null (url->user);
+ xfree_null (url->passwd);
xfree (url->dir);
xfree (url->file);
/* Miscellaneous declarations.
- Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998, 2003 Free Software Foundation, Inc.
This file is part of GNU Wget.
file, but you are not obligated to do so. If you do not wish to do
so, delete this exception statement from your version. */
-/* This file contains some declarations that don't fit anywhere else.
- It also contains some useful includes, like the obnoxious TIME_H
- inclusion. */
+/* This file contains declarations that are universally useful and
+ those that don't fit elsewhere. It also includes sysdep.h which
+ includes some often-needed system includes, like the obnoxious
+ <time.h> inclusion. */
#ifndef WGET_H
#define WGET_H
# include <libintl.h>
# endif /* HAVE_LIBINTL_H */
#else /* not HAVE_NLS */
-# define _(string) string
+# define _(string) (string)
#endif /* not HAVE_NLS */
/* No-op version of gettext, used for constant strings. */
/* Likewise for logging functions. */
#include "log.h"
-
-/* #### Find a better place for this. */
-/* The log file to which Wget writes to after HUP. */
-#define DEFAULT_LOGFILE "wget-log"
\f
/* Useful macros used across the code: */
/* The number of elements in an array. For example:
- static char a[] = "foo"; -- countof(a) == 4 (for terminating \0)
+ static char a[] = "foo"; -- countof(a) == 4 (note terminating \0)
int a[5] = {1, 2}; -- countof(a) == 5
char *a[] = { -- countof(a) == 3
"foo", "bar", "baz"
#define countof(array) (sizeof (array) / sizeof ((array)[0]))
/* Zero out a value. */
-#define xzero(x) memset (&(x), '\0', sizeof ((x)))
+#define xzero(x) memset (&(x), '\0', sizeof (x))
/* Convert an ASCII hex digit to the corresponding number between 0
- and 15. X should be a hexadecimal digit that satisfies isxdigit;
+ and 15. H should be a hexadecimal digit that satisfies isxdigit;
otherwise, the result is undefined. */
#define XDIGIT_TO_NUM(h) ((h) < 'A' ? (h) - '0' : TOUPPER (h) - 'A' + 10)
#define X2DIGITS_TO_NUM(h1, h2) ((XDIGIT_TO_NUM (h1) << 4) + XDIGIT_TO_NUM (h2))
/* The reverse of the above: convert a number in the [0, 16) range to
- the ASCII representation of the corresponding hex digit. The `+ 0'
- is so you don't accidentally use it as an lvalue. */
+ the ASCII representation of the corresponding hexadecimal digit.
+ `+ 0' is there so you can't accidentally use it as an lvalue. */
#define XNUM_TO_DIGIT(x) ("0123456789ABCDEF"[x] + 0)
#define XNUM_TO_digit(x) ("0123456789abcdef"[x] + 0)
/* Return non-zero if string bounded between BEG and END is equal to
STRING_LITERAL. The comparison is case-sensitive. */
-#define BOUNDED_EQUAL(beg, end, string_literal) \
- ((end) - (beg) == sizeof (string_literal) - 1 \
- && !memcmp ((beg), (string_literal), \
- sizeof (string_literal) - 1))
+#define BOUNDED_EQUAL(beg, end, string_literal) \
+ ((end) - (beg) == sizeof (string_literal) - 1 \
+ && !memcmp (beg, string_literal, sizeof (string_literal) - 1))
/* The same as above, except the comparison is case-insensitive. */
-#define BOUNDED_EQUAL_NO_CASE(beg, end, string_literal) \
- ((end) - (beg) == sizeof (string_literal) - 1 \
- && !strncasecmp ((beg), (string_literal), \
- sizeof (string_literal) - 1))
-
-/* Note that this much more elegant definition cannot be used:
-
- #define STRDUP_ALLOCA(str) (strcpy ((char *)alloca (strlen (str) + 1), str))
+#define BOUNDED_EQUAL_NO_CASE(beg, end, string_literal) \
+ ((end) - (beg) == sizeof (string_literal) - 1 \
+ && !strncasecmp (beg, string_literal, sizeof (string_literal) - 1))
- This is because some compilers don't handle alloca() as argument to
- function correctly. Gcc on Intel platforms has been reported to
- offend in this case. */
+/* Like ptr=strdup(str), but allocates the space for PTR on the stack.
+ This cannot be an expression because this is not portable:
+ #define STRDUP_ALLOCA(str) (strcpy (alloca (strlen (str) + 1), str))
+ The problem is that some compilers can't handle alloca() being an
+ argument to a function. */
#define STRDUP_ALLOCA(ptr, str) do { \
char **SA_dest = &(ptr); \
will realloc BASEVAR as necessary so that it can hold at least
NEEDED_SIZE objects. The reallocing is done by doubling, which
ensures constant amortized time per element. */
-#define DO_REALLOC(basevar, sizevar, needed_size, type) do { \
- /* Avoid side effects by prefixing the local vars. */ \
- long do_realloc_needed_size = (needed_size); \
- long do_realloc_newsize = 0; \
- while ((sizevar) < (do_realloc_needed_size)) { \
- do_realloc_newsize = 2*(sizevar); \
- if (do_realloc_newsize < 32) \
- do_realloc_newsize = 32; \
- (sizevar) = do_realloc_newsize; \
- } \
- if (do_realloc_newsize) \
- basevar = (type *)xrealloc (basevar, do_realloc_newsize * sizeof (type)); \
-} while (0)
-/* Free FOO if it is non-NULL. */
-#define FREE_MAYBE(foo) do { if (foo) xfree ((foo)); } while (0)
+#define DO_REALLOC(basevar, sizevar, needed_size, type) do { \
+ long DR_needed_size = (needed_size); \
+ long DR_newsize = 0; \
+ while ((sizevar) < (DR_needed_size)) { \
+ DR_newsize = sizevar << 1; \
+ if (DR_newsize < 16) \
+ DR_newsize = 16; \
+ (sizevar) = DR_newsize; \
+ } \
+ if (DR_newsize) \
+ basevar = (type *)xrealloc (basevar, DR_newsize * sizeof (type)); \
+} while (0)
extern const char *exec_name;
\f
SSLERRCERTFILE,SSLERRCERTKEY,SSLERRCTXCREATE
} uerr_t;
-/* These are not used widely. They should either be removed or used
- consistently. */
-typedef unsigned char boolean;
-#ifndef FALSE
-# define FALSE 0
-#endif
-#ifndef TRUE
-# define TRUE 1
-#endif
-
-/* For most options, 0 means no limits, but with -p in the picture,
- that causes a problem on the maximum recursion depth variable. To
- retain backwards compatibility we allow users to consider "0" to be
- synonymous with "inf" for -l, but internally infinite recursion is
- specified by -1 and 0 means to only retrieve the requisites of a
- single document. */
-#define INFINITE_RECURSION -1
-
/* In case old systems don't have EAFNOSUPPORT, which we use below. */
#ifndef EAFNOSUPPORT
# define EAFNOSUPPORT EINVAL
#define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type)))
+/* Free P if it is non-NULL. C requires free() to behaves this way by
+ default, but Wget's code is historically careful not to pass NULL
+ to free. This allows us to assert p!=NULL in xfree to check
+ additional errors. (But we currently don't do that!) */
+#define xfree_null(p) if (!(p)) ; else xfree (p)
+
#endif /* XMALLOC_H */