+2003-10-31 Hrvoje Niksic <hniksic@xemacs.org>
+
+ * various: Use new macros xnew, xnew0, xnew_array, and xnew0_array
+ in various places.
+
2003-10-31 Hrvoje Niksic <hniksic@xemacs.org>
* wget.h: Move declarations of malloc and logging code to
int optval;
struct sockaddr_storage ss;
struct sockaddr *sa = (struct sockaddr *)&ss;
- memset (&ss, 0, sizeof (ss));
+ xzero (ss);
#ifdef ENABLE_IPV6
if (bind_address->type == IPV6_ADDRESS)
list.
-- Hrvoje Niksic <hniksic@xemacs.org>
*/
- converted_file_ptr = xmalloc(sizeof(*converted_file_ptr));
- converted_file_ptr->string = xstrdup(file); /* die on out-of-mem. */
+ converted_file_ptr = xmalloc (sizeof (*converted_file_ptr));
+ converted_file_ptr->string = xstrdup (file);
converted_file_ptr->next = converted_files;
converted_files = converted_file_ptr;
}
struct cookie_jar *
cookie_jar_new (void)
{
- struct cookie_jar *jar = xmalloc (sizeof (struct cookie_jar));
+ struct cookie_jar *jar = xnew (struct cookie_jar);
jar->chains = make_nocase_string_hash_table (0);
jar->cookie_count = 0;
return jar;
static struct cookie *
cookie_new (void)
{
- struct cookie *cookie = xmalloc (sizeof (struct cookie));
- memset (cookie, '\0', sizeof (struct cookie));
+ struct cookie *cookie = xnew0 (struct cookie);
/* Both cookie->permanent and cookie->expiry_time are now 0. By
default, we assume that the cookie is non-permanent and valid
*store = '\0';
/* Workaround for extract() reads beyond end of data */
- memset (cp, 0, sizeof(cp));
+ xzero (cp);
memcpy (cp, c, 8);
/* Compute parity. */
for (p = 0, i = 0; i < 64; i += 2)
int ocerr = 0;
unsigned long curerr = 0;
char errbuff[1024];
- memset(errbuff, 0, sizeof(errbuff));
- while ( 0 != (curerr = ERR_get_error ()))
+ xzero (errbuff);
+ while ((curerr = ERR_get_error ()) != 0)
{
DEBUGP (("OpenSSL: %s\n", ERR_error_string (curerr, errbuff)));
++ocerr;
int (*test_function) (const void *, const void *))
{
int size;
- struct hash_table *ht
- = (struct hash_table *)xmalloc (sizeof (struct hash_table));
+ struct hash_table *ht = xnew (struct hash_table);
ht->hash_function = hash_function ? hash_function : ptrhash;
ht->test_function = test_function ? test_function : ptrcmp;
ht->resize_threshold = size * HASH_FULLNESS_THRESHOLD;
/*assert (ht->resize_threshold >= items);*/
- ht->mappings = xmalloc (ht->size * sizeof (struct mapping));
- memset (ht->mappings, '\0', ht->size * sizeof (struct mapping));
-
+ ht->mappings = xnew0_array (struct mapping, ht->size);
ht->count = 0;
return ht;
ht->size = newsize;
ht->resize_threshold = newsize * HASH_FULLNESS_THRESHOLD;
- mappings = xmalloc (ht->size * sizeof (struct mapping));
- memset (mappings, '\0', ht->size * sizeof (struct mapping));
- ht->mappings = mappings;
+ ht->mappings = mappings = xnew0_array (struct mapping, ht->size);
for (mp = old_mappings; mp < old_end; mp++)
if (NON_EMPTY (mp))
if (cnt == 0)
return NULL;
- al = xmalloc (sizeof (struct address_list));
- al->addresses = xmalloc (cnt * sizeof (ip_address));
+ al = xnew0 (struct address_list);
+ al->addresses = xnew_array (ip_address, cnt);
al->count = cnt;
- al->faulty = 0;
- al->from_cache = 0;
al->refcount = 1;
ip = al->addresses;
address_list_from_ipv4_addresses (char **h_addr_list)
{
int count, i;
- struct address_list *al = xmalloc (sizeof (struct address_list));
+ struct address_list *al = xnew0 (struct address_list);
count = 0;
while (h_addr_list[count])
++count;
assert (count > 0);
+ al->addresses = xnew_array (ip_address, count);
al->count = count;
- al->faulty = 0;
- al->addresses = xmalloc (count * sizeof (ip_address));
- al->from_cache = 0;
al->refcount = 1;
for (i = 0; i < count; i++)
flag. Without IPv6, we use inet_addr succeeds. */
#ifdef ENABLE_IPV6
- memset (&hints, 0, sizeof (hints));
+ xzero (hints);
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_NUMERICHOST;
#ifdef ENABLE_IPV6
{
- memset (&hints, 0, sizeof (hints));
+ xzero (hints);
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
if (flags & LH_PASSIVE)
DEBUGP (("appending \"%s\" to urlpos.\n", url->url));
- newel = (struct urlpos *)xmalloc (sizeof (struct urlpos));
- memset (newel, 0, sizeof (*newel));
-
+ newel = xnew0 (struct urlpos);
newel->next = NULL;
newel->url = url;
newel->pos = tag->attrs[attrind].value_raw_beginning - ctx->text;
}
xfree (url_text);
- entry = (struct urlpos *)xmalloc (sizeof (struct urlpos));
- memset (entry, 0, sizeof (*entry));
+ entry = xnew0 (struct urlpos);
entry->next = NULL;
entry->url = url;
NULL this way is technically illegal, but porting Wget to a
machine where NULL is not all-zero bit pattern will be the least
of the implementors' worries. */
- memset (&opt, 0, sizeof (opt));
+ xzero (opt);
opt.cookies = 1;
-
opt.verbose = -1;
opt.ntry = 20;
opt.reclevel = 5;
{
/* Allocate memory and concatenate the old and the new
contents. */
- ln->malloced_line = xmalloc (old_len + len + 1);
+ ln->malloced_line = (char *)xmalloc (old_len + len + 1);
memcpy (ln->malloced_line, ln->static_line,
old_len);
memcpy (ln->malloced_line + old_len, start, len);
return;
CHECK_VERBOSE (o);
- memset (&lpstate, '\0', sizeof (lpstate));
+ xzero (lpstate);
do
{
VA_START (args, fmt);
if (inhibit_logging)
return;
- memset (&lpstate, '\0', sizeof (lpstate));
+ xzero (lpstate);
do
{
VA_START (args, fmt);
static void *
dot_create (long initial, long total)
{
- struct dot_progress *dp = xmalloc (sizeof (struct dot_progress));
-
- memset (dp, 0, sizeof (*dp));
-
+ struct dot_progress *dp = xnew0 (struct dot_progress);
dp->initial_length = initial;
dp->total_length = total;
static void *
bar_create (long initial, long total)
{
- struct bar_progress *bp = xmalloc (sizeof (struct bar_progress));
-
- memset (bp, 0, sizeof (*bp));
+ struct bar_progress *bp = xnew0 (struct bar_progress);
/* In theory, our callers should take care of this pathological
case, but it can sometimes happen. */
static struct url_queue *
url_queue_new (void)
{
- struct url_queue *queue = xmalloc (sizeof (*queue));
- memset (queue, '\0', sizeof (*queue));
+ struct url_queue *queue = xnew0 (struct url_queue);
return queue;
}
url_enqueue (struct url_queue *queue,
const char *url, const char *referer, int depth, int html_allowed)
{
- struct queue_element *qel = xmalloc (sizeof (*qel));
+ struct queue_element *qel = xnew (struct queue_element);
qel->url = url;
qel->referer = referer;
qel->depth = depth;
new_parsed = url_parse (redirected, NULL);
assert (new_parsed != NULL);
- upos = xmalloc (sizeof (struct urlpos));
- memset (upos, 0, sizeof (*upos));
+ upos = xnew0 (struct urlpos);
upos->url = new_parsed;
success = download_child_p (upos, orig_parsed, depth,
for (i = 0; i < specs->count; i++)
if (specs->paths[i].user_agent_exact_p)
++cnt;
- newpaths = xmalloc (cnt * sizeof (struct path_info));
+ newpaths = xnew_array (struct path_info, cnt);
for (i = 0, j = 0; i < specs->count; i++)
if (specs->paths[i].user_agent_exact_p)
newpaths[j++] = specs->paths[i];
the last `user-agent' instructions. */
int record_count = 0;
- struct robot_specs *specs = xmalloc (sizeof (struct robot_specs));
- memset (specs, '\0', sizeof (struct robot_specs));
+ struct robot_specs *specs = xnew0 (struct robot_specs);
while (1)
{
}
}
- u = (struct url *)xmalloc (sizeof (struct url));
- memset (u, 0, sizeof (*u));
-
+ u = xnew0 (struct url);
u->scheme = scheme;
u->host = strdupdelim (host_b, host_e);
u->port = port;
fd = open (file, O_RDONLY);
if (fd < 0)
return NULL;
- fm = xmalloc (sizeof (struct file_memory));
+ fm = xnew (struct file_memory);
#ifdef HAVE_MMAP
{
slist *
slist_append (slist *l, const char *s)
{
- slist *newel = (slist *)xmalloc (sizeof (slist));
+ slist *newel = xnew (slist);
slist *beg = l;
newel->string = xstrdup (s);
slist *
slist_prepend (slist *l, const char *s)
{
- slist *newel = (slist *)xmalloc (sizeof (slist));
+ slist *newel = xnew (slist);
newel->string = xstrdup (s);
newel->next = l;
return newel;
struct wget_timer *
wtimer_allocate (void)
{
- struct wget_timer *wt =
- (struct wget_timer *)xmalloc (sizeof (struct wget_timer));
+ struct wget_timer *wt = xnew (struct wget_timer);
return wt;
}
#ifdef ITIMER_REAL
/* Use the modern itimer interface. */
struct itimerval itv;
- memset (&itv, 0, sizeof (itv));
+ xzero (itv);
itv.it_value.tv_sec = (long) timeout;
itv.it_value.tv_usec = 1000000L * (timeout - (long)timeout);
if (itv.it_value.tv_sec == 0 && itv.it_value.tv_usec == 0)
{
#ifdef ITIMER_REAL
struct itimerval disable;
- memset (&disable, 0, sizeof (disable));
+ xzero (disable);
setitimer (ITIMER_REAL, &disable, NULL);
#else /* not ITIMER_REAL */
alarm (0);
#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;