bug-gnulib
[Top][All Lists]
Advanced

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

removed lchown.h and migrated lchown decl into unistd.h


From: Paul Eggert
Subject: removed lchown.h and migrated lchown decl into unistd.h
Date: Fri, 15 Jun 2007 23:13:48 -0700
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

I installed this into gnulib to clean up the lchown declaration
situation.  The only tricky bit was to convince unistd.h to not
replace chown when compiling lchown.c, when lchown.c wants a
nonstandard system chown that doesn't follow symlinks.

2007-06-15  Paul Eggert  <address@hidden>

        Revamp lchown so that it lives in unistd.h where it belongs.
        * lib/lchown.h: Remove.
        * lib/dirchownmod.c: Don't include lib/lchown.h.
        * lib/fchownat.c: Likewise.
        * lib/openat.c: Likewise.
        * lib/lchown.c (REPLACE_CHOWN): Define to 0 if the system chown
        does not follow symlinks.
        (EOPNOTSUPP): Define if not defined.
        * lib/unistd_.h (chown): Do not replace if REPLADE_CHOWN
        is defined to 0.
        (lchown): New decl.
        * m4/lchown.m4 (gl_FUNC_LCHOWN): Require gl_UNISTD_H_DEFAULTS.
        Do not check for lchown decl.
        Set REPLACE_LCHOWN.
        * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Set GNULIB_LCHOWN,
        REPLACE_LCHOWN.
        * modules/chown: Make it clear it follows symlinks.
        * modules/lchown: Make it clear it doesn't follow symlinks.
        (Files): Remove lib/lchown.h
        (Depends-on): Add unistd.
        (configure.ac): Add gl_UNISTD_MODULE_INDICATOR([lchown]).
        (Include): Include <unistd.h>, not "lchown.h".
        * modules/unistd (unistd.h): Substitude GNULIB_LCHOWN and
        REPLACE_LCHOWN.

Index: lib/lchown.h
===================================================================
RCS file: lib/lchown.h
diff -N lib/lchown.h
--- lib/lchown.h        5 Oct 2006 22:49:57 -0000       1.4
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,42 +0,0 @@
-/* Declare a replacement for lchown on hosts that lack it.
-
-   Copyright (C) 2006 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 2, 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, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Jim Meyering.  */
-
-#include <errno.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#if HAVE_DECL_LCHOWN
-# if ! HAVE_LCHOWN
-#  undef lchown
-#  define lchown rpl_chown
-# endif
-#else
-int lchown (char const *, uid_t, gid_t);
-#endif
-
-/* Some systems don't have EOPNOTSUPP.  */
-#ifndef EOPNOTSUPP
-# ifdef ENOTSUP
-#  define EOPNOTSUPP ENOTSUP
-# else
-/* Some systems don't have ENOTSUP either.  */
-#  define EOPNOTSUPP EINVAL
-# endif
-#endif
Index: lib/dirchownmod.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/dirchownmod.c,v
retrieving revision 1.6
diff -u -p -r1.6 dirchownmod.c
--- lib/dirchownmod.c   5 Oct 2006 22:49:57 -0000       1.6
+++ lib/dirchownmod.c   16 Jun 2007 06:10:41 -0000
@@ -1,6 +1,6 @@
 /* Change the ownership and mode bits of a directory.

-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007 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
@@ -28,7 +28,6 @@
 #include <unistd.h>

 #include "lchmod.h"
-#include "lchown.h"
 #include "stat-macros.h"

 #ifndef HAVE_FCHMOD
Index: lib/fchownat.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/fchownat.c,v
retrieving revision 1.2
diff -u -p -r1.2 fchownat.c
--- lib/fchownat.c      18 Mar 2007 15:29:10 -0000      1.2
+++ lib/fchownat.c      16 Jun 2007 06:10:41 -0000
@@ -29,7 +29,6 @@
 #include <unistd.h>

 #include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
-#include "lchown.h"
 #include "save-cwd.h"
 #include "openat-priv.h"

Index: lib/openat.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/openat.c,v
retrieving revision 1.16
diff -u -p -r1.16 openat.c
--- lib/openat.c        24 Dec 2006 17:08:04 -0000      1.16
+++ lib/openat.c        16 Jun 2007 06:10:41 -0000
@@ -1,5 +1,5 @@
 /* provide a replacement openat function
-   Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006, 2007 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
@@ -26,7 +26,6 @@

 #include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
 #include "fcntl--.h"
-#include "lchown.h"
 #include "lstat.h"
 #include "openat-priv.h"
 #include "save-cwd.h"
Index: lib/lchown.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/lchown.c,v
retrieving revision 1.20
diff -u -p -r1.20 lchown.c
--- lib/lchown.c        27 Oct 2006 20:46:43 -0000      1.20
+++ lib/lchown.c        16 Jun 2007 06:10:41 -0000
@@ -1,6 +1,6 @@
 /* Provide a stub lchown function for systems that lack it.

-   Copyright (C) 1998, 1999, 2002, 2004, 2006 Free Software
+   Copyright (C) 1998, 1999, 2002, 2004, 2006, 2007 Free Software
    Foundation, Inc.

    This program is free software; you can redistribute it and/or modify
@@ -21,10 +21,26 @@

 #include <config.h>

-#include "lchown.h"
+/* If the system chown does not follow symlinks, we don't want it
+   replaced by gnulib's chown, which does follow symlinks.  */
+#if CHOWN_MODIFIES_SYMLINK
+# define REPLACE_CHOWN 0
+#endif
+#include <unistd.h>

+#include <errno.h>
 #include <sys/stat.h>

+/* Some systems don't have EOPNOTSUPP.  */
+#ifndef EOPNOTSUPP
+# ifdef ENOTSUP
+#  define EOPNOTSUPP ENOTSUP
+# else
+/* Some systems don't have ENOTSUP either.  */
+#  define EOPNOTSUPP EINVAL
+# endif
+#endif
+
 /* Work just like chown, except when FILE is a symbolic link.
    In that case, set errno to EOPNOTSUPP and return -1.
    But if autoconf tests determined that chown modifies
Index: lib/unistd_.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/unistd_.h,v
retrieving revision 1.11
diff -u -p -r1.11 unistd_.h
--- lib/unistd_.h       30 May 2007 02:16:53 -0000      1.11
+++ lib/unistd_.h       16 Jun 2007 06:10:41 -0000
@@ -49,13 +49,18 @@ extern "C" {

 #if @GNULIB_CHOWN@
 # if @REPLACE_CHOWN@
+#  ifndef REPLACE_CHOWN
+#   define REPLACE_CHOWN 1
+#  endif
+#  if REPLACE_CHOWN
 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
-   to GID (if GID is not -1).
+   to GID (if GID is not -1).  Follow symbolic links.
    Return 0 if successful, otherwise -1 and errno set.
    See the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/chown.html>.  */
-#  define chown rpl_chown
+#   define chown rpl_chown
 extern int chown (const char *file, uid_t uid, gid_t gid);
+#  endif
 # endif
 #elif defined GNULIB_POSIXCHECK
 # undef chown
@@ -179,6 +184,25 @@ extern int getlogin_r (char *name, size_
 #endif


+#if @GNULIB_LCHOWN@
+# if @REPLACE_LCHOWN@
+/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
+   to GID (if GID is not -1).  Do not follow symbolic links.
+   Return 0 if successful, otherwise -1 and errno set.
+   See the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/lchown.html>.  */
+#  define lchown rpl_lchown
+extern int lchown (char const *file, uid_t owner, gid_t group);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lchown
+# define lchown(f,u,g) \
+    (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
+                      "systems - use gnulib module lchown for portability"), \
+     lchown (f, u, g))
+#endif
+
+
 #if @GNULIB_LSEEK@
 # if @REPLACE_LSEEK@
 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
Index: m4/lchown.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/lchown.m4,v
retrieving revision 1.12
diff -u -p -r1.12 lchown.m4
--- m4/lchown.m4        27 Oct 2006 20:46:43 -0000      1.12
+++ m4/lchown.m4        16 Jun 2007 06:10:41 -0000
@@ -1,7 +1,8 @@
-#serial 11
+#serial 12
+# Determine whether we need the lchown wrapper.

-dnl Copyright (C) 1998, 2001, 2003, 2004, 2005, 2006 Free Software
-dnl Foundation, Inc.
+dnl Copyright (C) 1998, 2001, 2003, 2004, 2005, 2006, 2007 Free
+dnl Software Foundation, Inc.

 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -12,8 +13,10 @@ dnl Provide lchown on systems that lack 

 AC_DEFUN([gl_FUNC_LCHOWN],
 [
-  AC_REQUIRE([AC_TYPE_UID_T])
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
   AC_REQUIRE([gl_FUNC_CHOWN])
-  AC_CHECK_DECLS_ONCE([lchown])
   AC_REPLACE_FUNCS(lchown)
+  if test $ac_cv_func_lchown = no; then
+    REPLACE_LCHOWN=1
+  fi
 ])
Index: m4/unistd_h.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/unistd_h.m4,v
retrieving revision 1.7
diff -u -p -r1.7 unistd_h.m4
--- m4/unistd_h.m4      24 May 2007 16:59:21 -0000      1.7
+++ m4/unistd_h.m4      16 Jun 2007 06:10:41 -0000
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 7
+# unistd_h.m4 serial 8
 dnl Copyright (C) 2006-2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -39,6 +39,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_FTRUNCATE=0;     AC_SUBST([GNULIB_FTRUNCATE])
   GNULIB_GETCWD=0;        AC_SUBST([GNULIB_GETCWD])
   GNULIB_GETLOGIN_R=0;    AC_SUBST([GNULIB_GETLOGIN_R])
+  GNULIB_LCHOWN=0;        AC_SUBST([GNULIB_LCHOWN])
   GNULIB_LSEEK=0;         AC_SUBST([GNULIB_LSEEK])
   GNULIB_READLINK=0;      AC_SUBST([GNULIB_READLINK])
   GNULIB_SLEEP=0;         AC_SUBST([GNULIB_SLEEP])
@@ -51,5 +52,6 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   REPLACE_CHOWN=0;        AC_SUBST([REPLACE_CHOWN])
   REPLACE_FCHDIR=0;       AC_SUBST([REPLACE_FCHDIR])
   REPLACE_GETCWD=0;       AC_SUBST([REPLACE_GETCWD])
+  REPLACE_LCHOWN=0;       AC_SUBST([REPLACE_LCHOWN])
   REPLACE_LSEEK=0;        AC_SUBST([REPLACE_LSEEK])
 ])
Index: modules/chown
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/chown,v
retrieving revision 1.11
diff -u -p -r1.11 chown
--- modules/chown       19 Feb 2007 02:24:42 -0000      1.11
+++ modules/chown       16 Jun 2007 06:10:41 -0000
@@ -1,5 +1,5 @@
 Description:
-chown() function: change ownership of a file.
+chown() function: change ownership of a file, following symlinks.

 Files:
 lib/chown.c
Index: modules/lchown
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/lchown,v
retrieving revision 1.13
diff -u -p -r1.13 lchown
--- modules/lchown      27 Oct 2006 20:46:43 -0000      1.13
+++ modules/lchown      16 Jun 2007 06:10:41 -0000
@@ -1,22 +1,23 @@
 Description:
-lchown() function: change ownership of a file.
+lchown() function: change ownership of a file, without following symlinks.

 Files:
-lib/lchown.h
 lib/lchown.c
 m4/lchown.m4

 Depends-on:
 chown
 sys_stat
+unistd

 configure.ac:
 gl_FUNC_LCHOWN
+gl_UNISTD_MODULE_INDICATOR([lchown])

 Makefile.am:

 Include:
-"lchown.h"
+<unistd.h>

 License:
 GPL
Index: modules/unistd
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/unistd,v
retrieving revision 1.10
diff -u -p -r1.10 unistd
--- modules/unistd      24 May 2007 16:59:22 -0000      1.10
+++ modules/unistd      16 Jun 2007 06:10:41 -0000
@@ -29,6 +29,7 @@ unistd.h: unistd_.h
              -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
              -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
              -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
+             -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
              -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
              -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
              -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
@@ -40,6 +41,7 @@ unistd.h: unistd_.h
              -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
              -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
              -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
+             -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
              -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
              < $(srcdir)/unistd_.h; \
        } > address@hidden




reply via email to

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