From e97114feaa74c5f0516d76dcde67601e26462e95 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 23 Sep 2009 14:13:00 -0600 Subject: [PATCH] lstat: avoid mingw compilation error 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 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 --- ChangeLog | 10 ++++++++++ lib/lstat.c | 23 ++++++++++++++++------- m4/lstat.m4 | 10 ++++++---- m4/sys_stat_h.m4 | 13 ++----------- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a4aebf6b..2baa04495 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2009-09-23 Eric Blake + 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 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. diff --git a/lib/lstat.c b/lib/lstat.c index a05f6747d..27a0cb510 100644 --- a/lib/lstat.c +++ b/lib/lstat.c @@ -20,11 +20,18 @@ #include +#if !HAVE_LSTAT +/* On systems that lack symlinks, our replacement 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 -#include -#undef __need_system_sys_stat_h +# define __need_system_sys_stat_h +# include +# include +# 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 +# include -#include -#include +# include +# include /* 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 */ diff --git a/m4/lstat.m4 b/m4/lstat.m4 index 74c78fe48..089d0ff59 100644 --- a/m4/lstat.m4 +++ b/m4/lstat.m4 @@ -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 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 ]) diff --git a/m4/sys_stat_h.m4 b/m4/sys_stat_h.m4 index df7b238a4..d37fea827 100644 --- a/m4/sys_stat_h.m4 +++ b/m4/sys_stat_h.m4 @@ -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]) -- 2.11.0