X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fxmalloc.c;h=8217c992d7ac7ab6365cd3dff8a1bc66aff38aff;hb=5253e5dce47355d4f4490616bafbbabe1097e393;hp=a9f1975b9507ecf40fb609a4ea14b9c26e292835;hpb=37f27c1b74b966c83e6fd2ffa74ed8817bf00e6e;p=gnulib.git diff --git a/lib/xmalloc.c b/lib/xmalloc.c index a9f1975b9..8217c992d 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -1,5 +1,5 @@ /* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc. + Copyright (C) 1990, 91, 92, 93, 94, 95, 96 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,38 +15,50 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H -#include +#if HAVE_CONFIG_H +# include #endif #if __STDC__ -#define VOID void +# define VOID void #else -#define VOID char +# define VOID char #endif #include #if STDC_HEADERS -#include +# include #else +VOID *calloc (); VOID *malloc (); VOID *realloc (); void free (); #endif -/* This is for other GNU distributions with internationalized messages. - The GNU C Library itself does not yet support such messages. */ -#if HAVE_LIBINTL_H +#if ENABLE_NLS # include +# define _(Text) gettext (Text) #else -# define gettext(msgid) (msgid) +# define textdomain(Domain) +# define _(Text) Text #endif +#include "error.h" + #ifndef EXIT_FAILURE -#define EXIT_FAILURE 1 +# define EXIT_FAILURE 1 +#endif + +/* Prototypes for functions defined here. */ +#if defined (__STDC__) && __STDC__ +static VOID *fixup_null_alloc (size_t n); +VOID *xmalloc (size_t n); +VOID *xcalloc (size_t n, size_t s); +VOID *xrealloc (VOID *p, size_t n); #endif + /* Exit value when the requested amount of memory is not available. The caller may set it to some other value. */ int xmalloc_exit_failure = EXIT_FAILURE; @@ -67,7 +79,7 @@ fixup_null_alloc (n) if (n == 0) p = malloc ((size_t) 1); if (p == 0) - error (xmalloc_exit_failure, 0, gettext ("Memory exhausted")); + error (xmalloc_exit_failure, 0, _("Memory exhausted")); return p; } @@ -85,6 +97,20 @@ xmalloc (n) return p; } +/* Allocate memory for N elements of S bytes, with error checking. */ + +VOID * +xcalloc (n, s) + size_t n, s; +{ + VOID *p; + + p = calloc (n, s); + if (p == 0) + p = fixup_null_alloc (n); + return p; +} + /* Change the size of an allocated block of memory P to N bytes, with error checking. If P is NULL, run xmalloc. */