summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2007-06-16 06:10:44 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2007-06-16 06:10:44 +0000
commit20b5ea915e5041b7d27d6d4fea6fc34a1d89dc45 (patch)
tree3073687a448de6ff93cf7ca71a432c5efd8de4c9
parentb6ccac4f09fe7d01cc0b2aeb7b23d028f520ecef (diff)
downloadgnulib-20b5ea915e5041b7d27d6d4fea6fc34a1d89dc45.tar.gz
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.
-rw-r--r--ChangeLog27
-rw-r--r--lib/dirchownmod.c3
-rw-r--r--lib/fchownat.c1
-rw-r--r--lib/lchown.c20
-rw-r--r--lib/lchown.h42
-rw-r--r--lib/openat.c3
-rw-r--r--lib/unistd_.h28
-rw-r--r--m4/lchown.m413
-rw-r--r--m4/unistd_h.m44
-rw-r--r--modules/chown2
-rw-r--r--modules/lchown7
-rw-r--r--modules/unistd2
12 files changed, 91 insertions, 61 deletions
diff --git a/ChangeLog b/ChangeLog
index 67a6d7a253..50180f0d74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2007-06-15 Paul Eggert <eggert@cs.ucla.edu>
+
+ 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.
+
2007-06-15 Jim Meyering <jim@meyering.net>
Change license (GPL to LGPL) of fsusage and dependents.
diff --git a/lib/dirchownmod.c b/lib/dirchownmod.c
index b3e9518086..25931e1f60 100644
--- a/lib/dirchownmod.c
+++ b/lib/dirchownmod.c
@@ -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
diff --git a/lib/fchownat.c b/lib/fchownat.c
index 801c92a07e..6a6fe0f99b 100644
--- a/lib/fchownat.c
+++ b/lib/fchownat.c
@@ -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"
diff --git a/lib/lchown.c b/lib/lchown.c
index fa0826edb9..4ed4742116 100644
--- a/lib/lchown.c
+++ b/lib/lchown.c
@@ -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
diff --git a/lib/lchown.h b/lib/lchown.h
deleted file mode 100644
index 6816d1f129..0000000000
--- a/lib/lchown.h
+++ /dev/null
@@ -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
diff --git a/lib/openat.c b/lib/openat.c
index cd496540e7..25eedbb056 100644
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -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"
diff --git a/lib/unistd_.h b/lib/unistd_.h
index f34bc66c17..2409005310 100644
--- a/lib/unistd_.h
+++ b/lib/unistd_.h
@@ -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_t 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.
diff --git a/m4/lchown.m4 b/m4/lchown.m4
index a7b357297f..b719ed074c 100644
--- a/m4/lchown.m4
+++ b/m4/lchown.m4
@@ -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 it.
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
])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index 60dd73081a..90e1eaa32d 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -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])
])
diff --git a/modules/chown b/modules/chown
index a8ac9531bb..9e479a5090 100644
--- a/modules/chown
+++ b/modules/chown
@@ -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
diff --git a/modules/lchown b/modules/lchown
index 3607c079c5..e011e2bddb 100644
--- a/modules/lchown
+++ b/modules/lchown
@@ -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
diff --git a/modules/unistd b/modules/unistd
index 6bf946061b..3529b03c57 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -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; \
} > $@-t