changeset 34222:c94edf5a1c4c

careadlink: fix compilation error on mingw Mingw compilation failed: lib/careadlinkat.c: In function 'careadlinkat': lib/careadlinkat.c:143:39: error: 'const struct allocator' has no member named 'malloc' lib/careadlinkat.c:149:66: error: 'const struct allocator' has no member named 'realloc' lib/careadlinkat.c:152:39: error: 'const struct allocator' has no member named 'realloc' lib/careadlinkat.c:169:27: error: 'const struct allocator' has no member named 'malloc' make[4]: *** [careadlinkat.lo] Error 1 because "careadlinkat.h" includes enough system headers to get replacement names defined for malloc, then "allocator.h" defines fields with those replacement names, then undefining the macros tries to reference missing fields. I figured this patch is less invasive than changing the field names in allocator.h, and possibly requiring clients to change. * lib/careadlinkat.c (standard_allocator): Avoid renaming fields within struct allocator. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Fri, 08 Apr 2011 08:51:56 -0600
parents 041e04c6fdc8
children 4a1c19b03dd1
files ChangeLog lib/careadlinkat.c
diffstat 2 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Apr 06 14:33:24 2011 -0600
+++ b/ChangeLog	Fri Apr 08 08:51:56 2011 -0600
@@ -1,3 +1,9 @@
+2011-04-08  Eric Blake  <eblake@redhat.com>
+
+	careadlink: fix compilation error on mingw
+	* lib/careadlinkat.c (standard_allocator): Avoid renaming fields
+	within struct allocator.
+
 2011-04-06  Eric Blake  <eblake@redhat.com>
 
 	binary-io: relicense under LGPLv2+
--- a/lib/careadlinkat.c	Wed Apr 06 14:33:24 2011 -0600
+++ b/lib/careadlinkat.c	Fri Apr 08 08:51:56 2011 -0600
@@ -30,11 +30,6 @@
 #include <string.h>
 #include <unistd.h>
 
-/* Use the system functions, not the gnulib overrides, because this
-   module does not depend on GNU or POSIX semantics.  */
-#undef malloc
-#undef realloc
-
 /* Define this independently so that stdint.h is not a prerequisite.  */
 #ifndef SIZE_MAX
 # define SIZE_MAX ((size_t) -1)
@@ -57,10 +52,10 @@
 }
 #endif
 
-/* A standard allocator.  For now, only careadlinkat needs this, but
-   perhaps it should be moved to the allocator module.  */
-static struct allocator const standard_allocator =
-  { malloc, realloc, free, NULL };
+/* Forward declaration.  We want to #undef malloc before initializing
+   this struct, but cannot do so until after all code that uses named
+   fields from "allocator.h" has been compiled.  */
+static struct allocator const standard_allocator;
 
 /* Assuming the current directory is FD, get the symbolic link value
    of FILENAME as a null-terminated string and put it into a buffer.
@@ -173,3 +168,14 @@
   errno = ENOMEM;
   return NULL;
 }
+
+/* Use the system functions, not the gnulib overrides, because this
+   module does not depend on GNU or POSIX semantics.  See comments
+   above why this must occur here.  */
+#undef malloc
+#undef realloc
+
+/* A standard allocator.  For now, only careadlinkat needs this, but
+   perhaps it should be moved to the allocator module.  */
+static struct allocator const standard_allocator =
+  { malloc, realloc, free, NULL };