lstat: avoid mingw compilation error
authorEric Blake <ebb9@byu.net>
Wed, 23 Sep 2009 20:13:00 +0000 (14:13 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 24 Sep 2009 01:34:33 +0000 (19:34 -0600)
The openat module required lstat, but then repeated the checks
for whether lstat worked.  When cross-compiling to mingw, this
led to a wrong answer and tried compiling lstat.c, even though it
was not necessary, with a result of a compiler warning about
undeclared lstat.

* m4/lstat.m4 (gl_FUNC_LSTAT): Avoid duplicate calls to
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK, and deal with missing
lstat ourselves.
* lib/lstat.c [!HAVE_LSTAT]: Do nothing if <sys/stat.h> override
was adequate.
* m4/sys_stat_h.m4 (gl_HEADER_SYS_STAT_H): Let lstat module handle
the checks for lstat.
(gl_SYS_STAT_H_DEFAULTS): Set default for HAVE_LSTAT.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/lstat.c
m4/lstat.m4
m4/sys_stat_h.m4

index 8a4aebf..2baa044 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-09-23  Eric Blake  <ebb9@byu.net>
 
+       lstat: avoid mingw compilation error
+       * m4/lstat.m4 (gl_FUNC_LSTAT): Avoid duplicate calls to
+       AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK, and deal with missing
+       lstat ourselves.
+       * lib/lstat.c [!HAVE_LSTAT]: Do nothing if <sys/stat.h> override
+       was adequate.
+       * m4/sys_stat_h.m4 (gl_HEADER_SYS_STAT_H): Let lstat module handle
+       the checks for lstat.
+       (gl_SYS_STAT_H_DEFAULTS): Set default for HAVE_LSTAT.
+
        link: fix test failure on Solaris 9
        * lib/link.c (rpl_link): Don't assume link will catch bogus
        trailing slash on source.
index a05f674..27a0cb5 100644 (file)
 
 #include <config.h>
 
+#if !HAVE_LSTAT
+/* On systems that lack symlinks, our replacement <sys/stat.h> already
+   defined lstat as stat, so there is nothing further to do other than
+   avoid an empty file.  */
+typedef int dummy;
+#else /* HAVE_LSTAT */
+
 /* Get the original definition of lstat.  It might be defined as a macro.  */
-#define __need_system_sys_stat_h
-#include <sys/types.h>
-#include <sys/stat.h>
-#undef __need_system_sys_stat_h
+# define __need_system_sys_stat_h
+# include <sys/types.h>
+# include <sys/stat.h>
+# undef __need_system_sys_stat_h
 
 static inline int
 orig_lstat (const char *filename, struct stat *buf)
@@ -33,10 +40,10 @@ orig_lstat (const char *filename, struct stat *buf)
 }
 
 /* Specification.  */
-#include <sys/stat.h>
+# include <sys/stat.h>
 
-#include <string.h>
-#include <errno.h>
+# include <string.h>
+# include <errno.h>
 
 /* lstat works differently on Linux and Solaris systems.  POSIX (see
    `pathname resolution' in the glossary) requires that programs like
@@ -81,3 +88,5 @@ rpl_lstat (const char *file, struct stat *sbuf)
     }
   return stat (file, sbuf);
 }
+
+#endif /* HAVE_LSTAT */
index 74c78fe..089d0ff 100644 (file)
@@ -1,4 +1,4 @@
-# serial 19
+# serial 20
 
 # Copyright (C) 1997-2001, 2003-2009 Free Software Foundation, Inc.
 #
@@ -12,15 +12,17 @@ AC_DEFUN([gl_FUNC_LSTAT],
 [
   AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
   dnl If lstat does not exist, the replacement <sys/stat.h> does
-  dnl "#define lstat stat", and lstat.c does not need to be compiled.
+  dnl "#define lstat stat", and lstat.c is a no-op.
   AC_CHECK_FUNCS_ONCE([lstat])
   if test $ac_cv_func_lstat = yes; then
-    AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
-    dnl Note: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK does AC_LIBOBJ([lstat]).
+    AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
     if test $ac_cv_func_lstat_dereferences_slashed_symlink = no; then
+      dnl Note: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK does AC_LIBOBJ([lstat]).
       REPLACE_LSTAT=1
     fi
     # Prerequisites of lib/lstat.c.
     AC_REQUIRE([AC_C_INLINE])
+  else
+    HAVE_LSTAT=0
   fi
 ])
index df7b238..d37fea8 100644 (file)
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 16   -*- Autoconf -*-
+# sys_stat_h.m4 serial 17   -*- Autoconf -*-
 dnl Copyright (C) 2006-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -11,16 +11,6 @@ AC_DEFUN([gl_HEADER_SYS_STAT_H],
 [
   AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
 
-  dnl Check for lstat.  Systems that lack it (mingw) also lack symlinks, so
-  dnl stat is a good replacement.
-  AC_CHECK_FUNCS_ONCE([lstat])
-  if test $ac_cv_func_lstat = yes; then
-    HAVE_LSTAT=1
-  else
-    HAVE_LSTAT=0
-  fi
-  AC_SUBST([HAVE_LSTAT])
-
   dnl For the mkdir substitute.
   AC_REQUIRE([AC_C_INLINE])
 
@@ -61,6 +51,7 @@ AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
   HAVE_FCHMODAT=1;    AC_SUBST([HAVE_FCHMODAT])
   HAVE_FSTATAT=1;     AC_SUBST([HAVE_FSTATAT])
   HAVE_LCHMOD=1;      AC_SUBST([HAVE_LCHMOD])
+  HAVE_LSTAT=1;       AC_SUBST([HAVE_LSTAT])
   HAVE_MKDIRAT=1;     AC_SUBST([HAVE_MKDIRAT])
   HAVE_MKFIFOAT=1;    AC_SUBST([HAVE_MKFIFOAT])
   HAVE_MKNODAT=1;     AC_SUBST([HAVE_MKNODAT])