diff options
author | Jim Meyering <jim@meyering.net> | 1996-10-17 01:58:19 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1996-10-17 01:58:19 +0000 |
commit | 12b45785955e83a0cb4e835fd8abdcc96d99a1b8 (patch) | |
tree | a8c208abd4b1080c0d0211002ca3429ccbd0afba /lib | |
parent | e98991ee519eaac78900f133eebc4f06ea842aab (diff) | |
download | coreutils-12b45785955e83a0cb4e835fd8abdcc96d99a1b8.tar.xz |
libitize
Diffstat (limited to 'lib')
-rw-r--r-- | lib/xmalloc.c | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 33ac504e2..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,7 +15,7 @@ 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 +#if HAVE_CONFIG_H # include <config.h> #endif @@ -30,23 +30,35 @@ #if STDC_HEADERS # include <stdlib.h> #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 <libintl.h> +# 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 #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. */ |