Move the lstat() declaration to <sys/stat.h>.
authorBruno Haible <bruno@clisp.org>
Mon, 20 Oct 2008 23:05:43 +0000 (01:05 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 20 Oct 2008 23:05:43 +0000 (01:05 +0200)
ChangeLog
NEWS
lib/fts.c
lib/lstat.c
lib/lstat.h [deleted file]
lib/openat.c
lib/sys_stat.in.h
m4/lstat.m4
m4/sys_stat_h.m4
modules/lstat
modules/sys_stat

index 54fc51c..4b3429d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
 2008-10-20  Bruno Haible  <bruno@clisp.org>
 
+       * lib/fts.c: Don't include lstat.h.
+       * lib/openat.c: Include <sys/stat.h> instead of lstat.h.
+
+       Move the lstat() declaration to <sys/stat.h>.
+       * lib/lstat.h: Remove file.
+       * lib/sys_stat.in.h: Add special invocation convention.
+       (lstat): New declaration.
+       * lib/lstat.c (orig_lstat): New function.
+       (rpl_lstat): Use orig_lstat instead of lstat.
+       * m4/lstat.m4 (gl_FUNC_LSTAT): Require gl_SYS_STAT_H_DEFAULTS and
+       AC_C_INLINE. Set REPLACE_LSTAT.
+       * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Initialize GNULIB_LSTAT
+       and REPLACE_LSTAT.
+       * modules/lstat (Files): Remove lib/lstat.h.
+       (configure.ac): Invoke gl_SYS_STAT_MODULE_INDICATOR.
+       (Include): Specify <sys/stat.h> instead of lstat.h.
+       * modules/sys_stat (Makefile.am): Substitute GNULIB_LSTAT and
+       REPLACE_LSTAT.
+       * NEWS: Mention the change.
+
+2008-10-20  Bruno Haible  <bruno@clisp.org>
+
        * modules/posix_spawn-tests: New file.
        * tests/test-posix_spawn3.c: New file.
 
diff --git a/NEWS b/NEWS
index 8e8931e..0602705 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2008-10-20  lstat           The include file is changed from "lstat.h" to
+                            <sys/stat.h>.
+
 2008-10-20  getaddrinfo     The include file is changed from "getaddrinfo.h"
                             to <netdb.h>.
 
index 0428706..2054864 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -69,7 +69,6 @@ static char sccsid[] = "@(#)fts.c     8.6 (Berkeley) 8/14/94";
 
 #if ! _LIBC
 # include "fcntl--.h"
-# include "lstat.h"
 # include "openat.h"
 # include "unistd--.h"
 # include "same-inode.h"
index 9dcb4cd..3e07270 100644 (file)
@@ -1,7 +1,6 @@
 /* Work around a bug of lstat on some systems
 
-   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free
-   Software Foundation, Inc.
+   Copyright (C) 1997-1999, 2000-2006, 2008 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include <config.h>
 
-/* The specification of these functions is in sys_stat.h.  But we cannot
-   include this include file here, because on some systems, a
-   "#define lstat lstat64" is being used, and sys_stat.h deletes this
-   definition.  */
-
+/* Get the original definition of open.  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
+
+static inline int
+orig_lstat (const char *filename, struct stat *buf)
+{
+  return lstat (filename, buf);
+}
+
+/* Specification.  */
+#include <sys/stat.h>
+
 #include <string.h>
 #include <errno.h>
 
@@ -47,7 +54,7 @@ int
 rpl_lstat (const char *file, struct stat *sbuf)
 {
   size_t len;
-  int lstat_result = lstat (file, sbuf);
+  int lstat_result = orig_lstat (file, sbuf);
 
   if (lstat_result != 0 || !S_ISLNK (sbuf->st_mode))
     return lstat_result;
diff --git a/lib/lstat.h b/lib/lstat.h
deleted file mode 100644 (file)
index 63b21c8..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Retrieving information about files.
-   Copyright (C) 2005 Free Software Foundation, Inc.
-
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#include <sys/stat.h>
-
-#if !LSTAT_FOLLOWS_SLASHED_SYMLINK
-extern int rpl_lstat (const char *name, struct stat *buf);
-# undef lstat
-# define lstat rpl_lstat
-#endif
index 73f24b0..0c32672 100644 (file)
@@ -1,5 +1,5 @@
 /* provide a replacement openat function
-   Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include <stdarg.h>
 #include <stddef.h>
+#include <sys/stat.h>
 
 #include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
 #include "fcntl--.h"
-#include "lstat.h"
 #include "openat-priv.h"
 #include "save-cwd.h"
 
index fef9dd6..aeca760 100644 (file)
    incomplete.  It is intended to provide definitions and prototypes
    needed by an application.  Start with what the system provides.  */
 
-#ifndef _GL_SYS_STAT_H
-
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
 #endif
 
+#if defined __need_system_sys_stat_h
+/* Special invocation convention.  */
+
+#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef _GL_SYS_STAT_H
+
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
 
 #if ! @HAVE_LSTAT@
 # define lstat stat
 #endif
+#if @GNULIB_LSTAT@ && @REPLACE_LSTAT@
+# undef lstat
+# define lstat rpl_lstat
+extern int rpl_lstat (const char *name, struct stat *buf);
+#endif
+
 
 #if @REPLACE_MKDIR@
 # undef mkdir
@@ -322,3 +336,4 @@ extern int lchmod (const char *filename, mode_t mode);
 
 #endif /* _GL_SYS_STAT_H */
 #endif /* _GL_SYS_STAT_H */
+#endif
index b9777a6..9ac109f 100644 (file)
@@ -1,6 +1,6 @@
-#serial 16
+#serial 17
 
-# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007
+# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008
 # Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
@@ -11,7 +11,13 @@ dnl From Jim Meyering.
 
 AC_DEFUN([gl_FUNC_LSTAT],
 [
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
   AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
   dnl Note: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK does AC_LIBOBJ(lstat).
+  if test $ac_cv_func_lstat_dereferences_slashed_symlink = no; then
+    REPLACE_LSTAT=1
+  fi
+  # Prerequisites of lib/lstat.c.
+  AC_REQUIRE([AC_C_INLINE])
   :
 ])
index 3fb6b5c..20c82ed 100644 (file)
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 9   -*- Autoconf -*-
+# sys_stat_h.m4 serial 10   -*- Autoconf -*-
 dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -51,7 +51,9 @@ AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
 AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
 [
   GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD])
+  GNULIB_LSTAT=0;  AC_SUBST([GNULIB_LSTAT])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_LCHMOD=1;   AC_SUBST([HAVE_LCHMOD])
+  REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT])
   REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
 ])
index f2055f9..af416aa 100644 (file)
@@ -3,7 +3,6 @@ lstat() function: return information about a file or symbolic link.
 
 Files:
 lib/lstat.c
-lib/lstat.h
 m4/lstat.m4
 
 Depends-on:
@@ -11,11 +10,12 @@ sys_stat
 
 configure.ac:
 gl_FUNC_LSTAT
+gl_SYS_STAT_MODULE_INDICATOR([lstat])
 
 Makefile.am:
 
 Include:
-"lstat.h"
+<sys/stat.h>
 
 License:
 LGPL
index 84a7f36..56a11c2 100644 (file)
@@ -26,8 +26,10 @@ sys/stat.h: sys_stat.in.h
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
              -e 's|@''GNULIB_LCHMOD''@|$(GNULIB_LCHMOD)|g' \
+             -e 's|@''GNULIB_LSTAT''@|$(GNULIB_LSTAT)|g' \
              -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \
              -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
+             -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
              -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/sys_stat.in.h; \