123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #if HAVE_CONFIG_H
- # include <config.h>
- #endif
- #include <sys/types.h>
- #if STDC_HEADERS
- # include <stdlib.h>
- #else
- void *calloc ();
- void *malloc ();
- void *realloc ();
- void free ();
- #endif
- #if ENABLE_NLS
- # include <libintl.h>
- # define _(Text) gettext (Text)
- #else
- # define textdomain(Domain)
- # define _(Text) Text
- #endif
- #define N_(Text) Text
- #include "error.h"
- #include "xalloc.h"
- #ifndef EXIT_FAILURE
- # define EXIT_FAILURE 1
- #endif
- #ifndef HAVE_DONE_WORKING_MALLOC_CHECK
- "you must run the autoconf test for a properly working malloc -- see malloc.m4"
- #endif
- #ifndef HAVE_DONE_WORKING_REALLOC_CHECK
- "you must run the autoconf test for a properly working realloc --see realloc.m4"
- #endif
- int xalloc_exit_failure = EXIT_FAILURE;
- void (*xalloc_fail_func) PARAMS ((void)) = 0;
- char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
- void
- xalloc_die (void)
- {
- if (xalloc_fail_func)
- (*xalloc_fail_func) ();
- error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
-
- exit (EXIT_FAILURE);
- }
- void *
- xmalloc (size_t n)
- {
- void *p;
- p = malloc (n);
- if (p == 0)
- xalloc_die ();
- return p;
- }
- void *
- xrealloc (void *p, size_t n)
- {
- p = realloc (p, n);
- if (p == 0)
- xalloc_die ();
- return p;
- }
- void *
- xcalloc (size_t n, size_t s)
- {
- void *p;
- p = calloc (n, s);
- if (p == 0)
- xalloc_die ();
- return p;
- }
|