[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pspp-cvs] Changes to pspp/src/alloc.c
From: |
Ben Pfaff |
Subject: |
[Pspp-cvs] Changes to pspp/src/alloc.c |
Date: |
Sun, 31 Jul 2005 17:42:52 -0400 |
Index: pspp/src/alloc.c
diff -u pspp/src/alloc.c:1.8 pspp/src/alloc.c:1.9
--- pspp/src/alloc.c:1.8 Wed May 25 02:31:32 2005
+++ pspp/src/alloc.c Sun Jul 31 21:42:46 2005
@@ -23,105 +23,10 @@
#include <stdlib.h>
#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 continous block of N_MEMB by SIZE elements, with all
- bits set to 0.
- Aborts if unsuccessful.
-*/
-void *
-xcalloc (size_t n_memb, size_t size)
-{
- const size_t prod = size * n_memb;
- void *vp = 0;
-
- if (prod == 0)
- return NULL;
-
- /* Trap overflow errors */
- assert ( prod >= size );
- assert ( prod >= n_memb ) ;
-
- vp = xmalloc ( prod );
- memset (vp, 0, prod);
- 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 ();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pspp-cvs] Changes to pspp/src/alloc.c,
Ben Pfaff <=