X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Falloc.c;h=015d3397c19f28bd511bfe51307ff25a366ebfc3;hb=86968643348c6479634a89929a3094df5ec5f8b1;hp=b25e7dc9dbb1f3187e288fa10430960e92f3d1ac;hpb=4fdeb2145d081ff1b84e3f6c99f9d1c048c0d64a;p=pspp diff --git a/src/alloc.c b/src/alloc.c index b25e7dc9db..015d3397c1 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -23,92 +23,10 @@ #include #include "error.h" #include "str.h" - -/* Public functions. */ - -/* Allocates a block of SIZE bytes and returns it. - If SIZE is 0, returns a null pointer. - Aborts if unsuccessful. */ -void * -xmalloc (size_t size) -{ - void *vp; - if (size == 0) - return NULL; - - vp = malloc (size); - if (!vp) - out_of_memory (); - - return vp; -} - -/* Allocates a block of SIZE bytes, fill it with all-bits-0, and - returns it. - If SIZE is 0, returns a null pointer. - Aborts if unsuccessful. */ -void * -xcalloc (size_t size) -{ - void *vp = xmalloc (size); - memset (vp, 0, size); - return vp; -} - -/* If SIZE is 0, then block PTR is freed and a null pointer is - returned. - Otherwise, if PTR is a null pointer, then a new block is allocated - and returned. - Otherwise, block PTR is reallocated to be SIZE bytes in size and - the new location of the block is returned. - Aborts if unsuccessful. */ -void * -xrealloc (void *ptr, size_t size) -{ - void *vp; - if (!size) - { - if (ptr) - free (ptr); - - return NULL; - } - - if (ptr) - vp = realloc (ptr, size); - else - vp = malloc (size); - - if (!vp) - out_of_memory (); - - return vp; -} - -/* Makes a copy of string S in malloc()'d memory and returns the copy. - S must not be a null pointer. */ -char * -xstrdup (const char *s) -{ - size_t size; - char *t; - - assert (s != NULL); - - size = strlen (s) + 1; - - t = malloc (size); - if (!t) - out_of_memory (); - - memcpy (t, s, size); - return t; -} /* Report an out-of-memory condition and abort execution. */ void out_of_memory (void) { - fprintf (stderr, "virtual memory exhausted\n"); - exit (EXIT_FAILURE); + xalloc_die (); }