]> Savannah Git Hosting - gnulib.git/commitdiff
Make it possible to compile realloc.c separately, unconditionally.
authorBruno Haible <bruno@clisp.org>
Sun, 31 Jan 2021 11:39:31 +0000 (12:39 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 31 Jan 2021 11:40:42 +0000 (12:40 +0100)
* modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR.
* lib/realloc.c: Don't define rpl_realloc if not needed.

ChangeLog
lib/realloc.c
modules/realloc-posix

index bc19d192fef5f18bfb7e350f663fe50b67716219..e9e2b36929ada53bd8854dd6a15432a1288ba359 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2021-01-31  Bruno Haible  <bruno@clisp.org>
 
+       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.
+
        Make it possible to compile malloc.c separately, unconditionally.
        * modules/malloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR.
        * lib/malloc.c: Don't define rpl_malloc if not needed.
index 35caeab7ed988f6808cacada823668f873317a69..51d8d21087b89d9f5e76dddccd5a212f451b5541 100644 (file)
 
 #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
index 8e4924d471c603f16e7873637925936c8f6478b4..7f481102b30ee11587d1a8e99131b0f954ac0908 100644 (file)
@@ -15,6 +15,7 @@ if test $REPLACE_REALLOC = 1; then
   AC_LIBOBJ([realloc])
 fi
 gl_STDLIB_MODULE_INDICATOR([realloc-posix])
+gl_MODULE_INDICATOR([realloc-posix])
 
 Makefile.am: