summaryrefslogtreecommitdiff
path: root/lib/xmalloc.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-11-03 05:25:44 +0000
committerJim Meyering <jim@meyering.net>1997-11-03 05:25:44 +0000
commitaafe49ef49f56842fb8c573c009128c03aa19a28 (patch)
treea923bae01a0d4a5be0e3d569627b9595edfb3019 /lib/xmalloc.c
parentc417b4e7905ee98eb215189079aee3e737a5f77d (diff)
downloadcoreutils-aafe49ef49f56842fb8c573c009128c03aa19a28.tar.xz
(xalloc_fail): Renamed from fixup_null_alloc.
(xcalloc): #ifdef-out unused function. (xrealloc): Remove code to work around deficient versions of realloc. Now we have an autoconf-enabled replacement version. (xmalloc): Remove code to work around deficient versions of malloc. Now we have an autoconf-enabled replacement version.
Diffstat (limited to 'lib/xmalloc.c')
-rw-r--r--lib/xmalloc.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/lib/xmalloc.c b/lib/xmalloc.c
index 3d417f927..e204ae47f 100644
--- a/lib/xmalloc.c
+++ b/lib/xmalloc.c
@@ -71,22 +71,12 @@ void error (int, int, const char *, ...);
void error ();
#endif
-static void *
-fixup_null_alloc (n)
- size_t n;
+static void
+xalloc_fail ()
{
- void *p;
-
- p = 0;
- if (n == 0)
- p = malloc ((size_t) 1);
- if (p == 0)
- {
- if (xalloc_fail_func)
- (*xalloc_fail_func) ();
- error (xalloc_exit_failure, 0, xalloc_msg_memory_exhausted);
- }
- return p;
+ if (xalloc_fail_func)
+ (*xalloc_fail_func) ();
+ error (xalloc_exit_failure, 0, xalloc_msg_memory_exhausted);
}
/* Allocate N bytes of memory dynamically, with error checking. */
@@ -99,21 +89,7 @@ xmalloc (n)
p = malloc (n);
if (p == 0)
- p = fixup_null_alloc (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);
+ xalloc_fail ();
return p;
}
@@ -126,10 +102,26 @@ xrealloc (p, n)
void *p;
size_t n;
{
- if (p == 0)
- return xmalloc (n);
p = realloc (p, n);
if (p == 0)
+ xalloc_fail ();
+ return p;
+}
+
+#ifdef NOT_USED
+
+/* 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;
}
+
+#endif /* NOT_USED */