bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

declare lstat in sys/stat.h


From: Bruno Haible
Subject: declare lstat in sys/stat.h
Date: Sun, 19 Oct 2008 18:12:16 +0200
User-agent: KMail/1.5.4

Hi Jim,

lstat() is declared in <sys/stat.h> according to POSIX. Here's a proposed
patch for gnulib to do the same.

The only tricky issue here is that on some systems we have a
"#define lstat lstat64", and this gets in the way of redefining the function
while at the same time reusing its original definition. But this problem was
already solved for open (remember "#define open open64").

2008-10-19  Bruno Haible  <address@hidden>

        * 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.
        * lib/fts.c: Don't include lstat.h.
        * lib/openat.c: Include <sys/stat.h> instead of lstat.h.

--- lib/lstat.h.orig    2008-10-19 18:06:44.000000000 +0200
+++ lib/lstat.h 2003-09-23 19:59:22.000000000 +0200
@@ -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
--- lib/sys_stat.in.h.orig      2008-10-19 18:06:44.000000000 +0200
+++ lib/sys_stat.in.h   2008-10-19 17:47:10.000000000 +0200
@@ -21,12 +21,20 @@
    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.  */
+
address@hidden@ @NEXT_SYS_STAT_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef _GL_SYS_STAT_H
+
 /* The include_next requires a split double-inclusion guard.  */
 address@hidden@ @NEXT_SYS_STAT_H@
 
@@ -272,6 +280,12 @@
 #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 @@
 
 #endif /* _GL_SYS_STAT_H */
 #endif /* _GL_SYS_STAT_H */
+#endif
--- lib/lstat.c.orig    2008-10-19 18:06:44.000000000 +0200
+++ lib/lstat.c 2008-10-19 17:52:35.000000000 +0200
@@ -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
@@ -20,13 +19,21 @@
 
 #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 @@
 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;
--- m4/lstat.m4.orig    2008-10-19 18:06:44.000000000 +0200
+++ m4/lstat.m4 2008-10-19 18:06:27.000000000 +0200
@@ -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 @@
 
 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])
   :
 ])
--- m4/sys_stat_h.m4.orig       2008-10-19 18:06:44.000000000 +0200
+++ m4/sys_stat_h.m4    2008-10-19 17:35:51.000000000 +0200
@@ -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_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])
 ])
--- modules/lstat.orig  2008-10-19 18:06:44.000000000 +0200
+++ modules/lstat       2008-10-19 17:41:24.000000000 +0200
@@ -3,7 +3,6 @@
 
 Files:
 lib/lstat.c
-lib/lstat.h
 m4/lstat.m4
 
 Depends-on:
@@ -11,11 +10,12 @@
 
 configure.ac:
 gl_FUNC_LSTAT
+gl_SYS_STAT_MODULE_INDICATOR([lstat])
 
 Makefile.am:
 
 Include:
-"lstat.h"
+<sys/stat.h>
 
 License:
 LGPL
--- modules/sys_stat.orig       2008-10-19 18:06:44.000000000 +0200
+++ modules/sys_stat    2008-10-19 17:34:46.000000000 +0200
@@ -26,8 +26,10 @@
              -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; \
--- NEWS.orig   2008-10-19 18:06:44.000000000 +0200
+++ NEWS        2008-10-19 17:36:37.000000000 +0200
@@ -6,6 +6,9 @@
 
 Date        Modules         Changes
 
+2008-10-19  lstat           The include file is changed from "lstat.h" to
+                            <sys/stat.h>.
+
 2008-10-19  isnanf          The include file is changed from "isnanf.h" to
                             <math.h>.
             isnand          The include file is changed from "isnand.h" to
--- lib/fts.c.orig      2008-10-19 18:06:44.000000000 +0200
+++ lib/fts.c   2008-10-19 17:54:37.000000000 +0200
@@ -69,7 +69,6 @@
 
 #if ! _LIBC
 # include "fcntl--.h"
-# include "lstat.h"
 # include "openat.h"
 # include "unistd--.h"
 # include "same-inode.h"
--- lib/openat.c.orig   2008-10-19 18:06:44.000000000 +0200
+++ lib/openat.c        2008-10-19 17:55:02.000000000 +0200
@@ -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
@@ -22,10 +22,10 @@
 
 #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"
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]