-#ifndef HAVE_MALLOC
-"you must run the autoconf test for a GNU libc compatible malloc"
-#endif
-
-#ifndef HAVE_REALLOC
-"you must run the autoconf test for a GNU libc compatible realloc"
-#endif
-
-/* If non NULL, call this function when memory is exhausted. */
-void (*xalloc_fail_func) (void) = 0;
-
-/* Return true if array of N objects, each of size S, cannot exist due
- to arithmetic overflow. S must be nonzero. */
-
-static inline bool
-array_size_overflow (size_t n, size_t s)
-{
- return SIZE_MAX / s < n;
-}
-
-/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
- before exiting when memory is exhausted. Goes through gettext. */
-char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
-
-void
-xalloc_die (void)
-{
- if (xalloc_fail_func)
- (*xalloc_fail_func) ();
- error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
- /* The `noreturn' cannot be given to error, since it may return if
- its first argument is 0. To help compilers understand the
- xalloc_die does terminate, call abort. */
- abort ();
-}
-
-/* Allocate an array of N objects, each with S bytes of memory,
- dynamically, with error checking. S must be nonzero. */
-
-inline void *
-xnmalloc (size_t n, size_t s)
-{
- void *p;
- if (array_size_overflow (n, s) || ! (p = malloc (n * s)))
- xalloc_die ();
- return p;
-}
-