]> sjero.net Git - wget/blobdiff - src/xmalloc.c
[svn] Remove K&R support.
[wget] / src / xmalloc.c
index ab5ac81211cc7b5337240e4d8bdde587e77ab197..96f1d188c8064cbc6426f86af81b21f6477fc58c 100644 (file)
@@ -31,12 +31,7 @@ so, delete this exception statement from your version.  */
 
 #include <stdio.h>
 #include <stdlib.h>
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else  /* not HAVE_STRING_H */
-# include <strings.h>
-#endif /* not HAVE_STRING_H */
-#include <sys/types.h>
+#include <string.h>
 #include <errno.h>
 #include <assert.h>
 
@@ -44,10 +39,6 @@ so, delete this exception statement from your version.  */
 #include "xmalloc.h"
 #include "hash.h"              /* for hash_pointer */
 
-#ifndef errno
-extern int errno;
-#endif
-
 /* This file implements several wrappers around the basic allocation
    routines.  This is done for two reasons: first, so that the callers
    of these functions need not check for errors, which is easy to
@@ -218,9 +209,8 @@ static int malloc_count, free_count;
 
 /* Home-grown hash table of mallocs: */
 
-#define SZ 100003              /* Prime number a little over 100,000.
-                                  Increase the table size if you need
-                                  to debug larger Wget runs.  */
+#define SZ 100003              /* Prime just over 100,000.  Increase
+                                  it to debug larger Wget runs.  */
 
 static struct {
   const void *ptr;
@@ -250,7 +240,11 @@ register_ptr (const void *ptr, const char *file, int line)
 {
   int i;
   if (malloc_count - free_count > SZ)
-    abort ();
+    {
+      fprintf (stderr, "Increase SZ to a larger value and recompile.\n");
+      fflush (stderr);
+      abort ();
+    }
 
   i = ptr_position (ptr);
   malloc_table[i].ptr = ptr;
@@ -301,8 +295,7 @@ print_malloc_debug_stats (void)
          malloc_count, free_count, malloc_count - free_count);
   for (i = 0; i < SZ; i++)
     if (malloc_table[i].ptr != NULL)
-      printf ("0x%0*lx: %s:%d\n", 2 * sizeof (void *),
-             (long) malloc_table[i].ptr,
+      printf ("0x%0*lx: %s:%d\n", PTR_FORMAT (malloc_table[i].ptr),
              malloc_table[i].file, malloc_table[i].line);
 }
 
@@ -365,8 +358,7 @@ debugging_free (void *ptr, const char *source_file, int source_line)
   if (!unregister_ptr (ptr))
     {
       fprintf (stderr, "%s: bad xfree(%0*lx) at %s:%d\n",
-              exec_name, 2 * sizeof (void *), (long) ptr,
-              source_file, source_line);
+              exec_name, PTR_FORMAT (ptr), source_file, source_line);
       abort ();
     }
   ++free_count;