From: Bruno Haible <bruno@clisp.org>
Date: Sat, 9 Sep 2023 09:26:46 +0000 (+0200)
Subject: chown, lchown: Revisit platforms.
X-Git-Tag: v1.0~794
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=11ee0fc8cdda3a58379f39d7144f5983b418ab3a;p=gnulib.git

chown, lchown: Revisit platforms.

* doc/posix-functions/chown.texi: Update platforms list.
* doc/posix-functions/lchown.texi: Likewise.
* lib/chown.c (rpl_chown): Add platform comments.
* lib/lchown.c: Likewise.
---

diff --git a/ChangeLog b/ChangeLog
index 2aec64130e..e2c5622011 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-09-09  Bruno Haible  <bruno@clisp.org>
+
+	chown, lchown: Revisit platforms.
+	* doc/posix-functions/chown.texi: Update platforms list.
+	* doc/posix-functions/lchown.texi: Likewise.
+	* lib/chown.c (rpl_chown): Add platform comments.
+	* lib/lchown.c: Likewise.
+
 2023-09-07  Paul Eggert  <eggert@cs.ucla.edu>
 
 	mbscasecmp: support GNULIB_MCEL_PREFER
diff --git a/doc/posix-functions/chown.texi b/doc/posix-functions/chown.texi
index 6a62a6039f..295ed21504 100644
--- a/doc/posix-functions/chown.texi
+++ b/doc/posix-functions/chown.texi
@@ -11,18 +11,20 @@ Portability problems fixed by Gnulib:
 @item
 Some platforms fail to detect trailing slash on non-directories, as in
 @code{chown("link-to-file/",uid,gid)}:
-FreeBSD 7.2, AIX 7.1, Solaris 9.
+macOS 12.5, FreeBSD 7.2, AIX 7.3.1, Solaris 9.
 @item
 Some platforms fail to update the change time when at least one
 argument was not @minus{}1, but no ownership changes resulted:
-OpenBSD 6.7.
+OpenBSD 7.2.
 @item
 When passed an argument of @minus{}1, some implementations really set the owner
 user/group id of the file to this value, rather than leaving that id of the
-file alone.
+file alone:
+some very old platforms.
 @item
 When applied to a symbolic link, some implementations don't dereference
-the symlink, i.e.@: they behave like @code{lchown}.
+the symlink, i.e.@: they behave like @code{lchown}:
+some very old platforms.
 @item
 This function is missing on some platforms; however, the replacement
 always fails with @code{ENOSYS}:
diff --git a/doc/posix-functions/lchown.texi b/doc/posix-functions/lchown.texi
index d9a95b7d23..74f3abcaeb 100644
--- a/doc/posix-functions/lchown.texi
+++ b/doc/posix-functions/lchown.texi
@@ -9,6 +9,14 @@ Gnulib module: lchown
 Portability problems fixed by Gnulib:
 @itemize
 @item
+This function is missing on some platforms; however, the replacement
+fails with @code{ENOSYS}:
+mingw, MSVC 14.
+@item
+This function is missing on some platforms; however, the replacement
+fails on symlinks:
+Minix 3.2.1.
+@item
 Some platforms fail to detect trailing slash on non-directories, as in
 @code{lchown("link-to-file/",uid,gid)}:
 FreeBSD 7.2, Solaris 9.
@@ -17,11 +25,6 @@ Some platforms fail to update the change time when at least one
 argument was not -1, but no ownership changes resulted.  However,
 without @code{lchmod}, the replacement only fixes this for non-symlinks:
 OpenBSD 4.0.
-@item
-This function is missing on some platforms; however, the replacement
-fails on symlinks if @code{chown} is supported, and fails altogether
-with @code{ENOSYS} otherwise:
-Minix 3.1.8, mingw, MSVC 14.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/chown.c b/lib/chown.c
index d735818afd..bf15e920b9 100644
--- a/lib/chown.c
+++ b/lib/chown.c
@@ -57,7 +57,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
   bool stat_valid = false;
   int result;
 
-# if CHOWN_CHANGE_TIME_BUG
+# if CHOWN_CHANGE_TIME_BUG /* OpenBSD 7.2 */
   if (gid != (gid_t) -1 || uid != (uid_t) -1)
     {
       if (stat (file, &st))
@@ -66,7 +66,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
     }
 # endif
 
-# if CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE
+# if CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE /* some very old platforms */
   if (gid == (gid_t) -1 || uid == (uid_t) -1)
     {
       /* Stat file to get id(s) that should remain unchanged.  */
@@ -79,7 +79,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
     }
 # endif
 
-# if CHOWN_MODIFIES_SYMLINK
+# if CHOWN_MODIFIES_SYMLINK /* some very old platforms */
   {
     /* Handle the case in which the system-supplied chown function
        does *not* follow symlinks.  Instead, it changes permissions
@@ -118,7 +118,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
   }
 # endif
 
-# if CHOWN_TRAILING_SLASH_BUG
+# if CHOWN_TRAILING_SLASH_BUG /* macOS 12.5, FreeBSD 7.2, AIX 7.3.1, Solaris 9 */
   if (!stat_valid)
     {
       size_t len = strlen (file);
@@ -129,7 +129,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
 
   result = chown (file, uid, gid);
 
-# if CHOWN_CHANGE_TIME_BUG
+# if CHOWN_CHANGE_TIME_BUG /* OpenBSD 7.2 */
   if (result == 0 && stat_valid
       && (uid == st.st_uid || uid == (uid_t) -1)
       && (gid == st.st_gid || gid == (gid_t) -1))
diff --git a/lib/lchown.c b/lib/lchown.c
index 19a68c052b..d474bc264e 100644
--- a/lib/lchown.c
+++ b/lib/lchown.c
@@ -30,7 +30,7 @@
 
 /* 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
+# if CHOWN_MODIFIES_SYMLINK /* native Windows and some very old platforms */
 #  undef chown
 # endif