diff options
author | Bruno Haible <bruno@clisp.org> | 2021-01-31 12:39:31 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-01-31 12:40:42 +0100 |
commit | 64bdee095f60ec708937d73132b95377e27a827e (patch) | |
tree | 9616db22290811ecb487c0593469018d1c209e13 /lib/realloc.c | |
parent | eae672ebce3fbb777670debd458905cfb2a0adc4 (diff) | |
download | gnulib-64bdee095f60ec708937d73132b95377e27a827e.tar.gz |
Make it possible to compile realloc.c separately, unconditionally.
* modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR.
* lib/realloc.c: Don't define rpl_realloc if not needed.
Diffstat (limited to 'lib/realloc.c')
-rw-r--r-- | lib/realloc.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/realloc.c b/lib/realloc.c index 35caeab7ed..51d8d21087 100644 --- a/lib/realloc.c +++ b/lib/realloc.c @@ -37,7 +37,11 @@ #include <stdlib.h> -#include <errno.h> +/* A function definition is only needed if NEED_REALLOC_GNU is defined above + or if the module 'realloc-posix' requests it. */ +#if NEED_REALLOC_GNU || (GNULIB_REALLOC_POSIX && !HAVE_REALLOC_POSIX) + +# include <errno.h> /* Change the size of an allocated block of memory P to N bytes, with error checking. If N is zero, change it to 1. If P is NULL, @@ -48,7 +52,7 @@ rpl_realloc (void *p, size_t n) { void *result; -#if NEED_REALLOC_GNU +# if NEED_REALLOC_GNU if (n == 0) { n = 1; @@ -57,23 +61,25 @@ rpl_realloc (void *p, size_t n) free (p); p = NULL; } -#endif +# endif if (p == NULL) { -#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE +# if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE if (n == 0) n = 1; -#endif +# endif result = malloc (n); } else result = realloc (p, n); -#if !HAVE_REALLOC_POSIX +# if !HAVE_REALLOC_POSIX if (result == NULL) errno = ENOMEM; -#endif +# endif return result; } + +#endif |