diff options
Diffstat (limited to 'lib/malloc/xmalloc.c')
-rw-r--r-- | lib/malloc/xmalloc.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/lib/malloc/xmalloc.c b/lib/malloc/xmalloc.c index a495d77..b037222 100644 --- a/lib/malloc/xmalloc.c +++ b/lib/malloc/xmalloc.c @@ -31,7 +31,16 @@ # include "ansi_stdlib.h" #endif /* HAVE_STDLIB_H */ -static void memory_error_and_abort (); +/* Generic pointer type. */ +#ifndef PTR_T + +#if defined (__STDC__) +# define PTR_T void * +#else +# define PTR_T char * +#endif + +#endif /* PTR_T */ /* **************************************************************** */ /* */ @@ -39,48 +48,46 @@ static void memory_error_and_abort (); /* */ /* **************************************************************** */ +static void +memory_error_and_abort (fname) + char *fname; +{ + fprintf (stderr, "%s: out of virtual memory\n", fname); + exit (2); +} + /* Return a pointer to free()able block of memory large enough to hold BYTES number of bytes. If the memory cannot be allocated, print an error message and abort. */ -char * +PTR_T xmalloc (bytes) - int bytes; + size_t bytes; { - char *temp; + PTR_T temp; - temp = (char *)malloc (bytes); + temp = malloc (bytes); if (temp == 0) memory_error_and_abort ("xmalloc"); return (temp); } -char * +PTR_T xrealloc (pointer, bytes) - char *pointer; - int bytes; + PTR_T pointer; + size_t bytes; { - char *temp; + PTR_T temp; - temp = pointer ? (char *)realloc (pointer, bytes) : (char *)malloc (bytes); + temp = pointer ? realloc (pointer, bytes) : malloc (bytes); if (temp == 0) memory_error_and_abort ("xrealloc"); return (temp); } -static void -memory_error_and_abort (fname) - char *fname; -{ - fprintf (stderr, "%s: out of virtual memory\n", fname); - exit (2); -} - -/* Use this as the function to call when adding unwind protects so we - don't need to know what free() returns. */ void xfree (string) - char *string; + PTR_T string; { if (string) free (string); |