From 8bc2863c9a53466fda8f50603df297df9233c285 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 17 Oct 1996 01:58:19 +0000 Subject: [PATCH] libitize --- lib/xmalloc.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 33ac504e29..8217c992d7 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 #endif @@ -30,23 +30,35 @@ #if STDC_HEADERS # 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 #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. */ -- 2.30.2