]> Savannah Git Hosting - gnulib.git/commitdiff
statat: now obsolete
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 9 Mar 2022 21:54:53 +0000 (13:54 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 9 Mar 2022 21:57:58 +0000 (13:57 -0800)
* lib/openat.h (statat, lstatat): Now deprecated.
All uses removed, and replaced with fstatat.
* modules/statat: Mark as obsolete, because it’s confusing:
it’s not clear whether it should use AT_NO_AUTOMOUNT,
which is implied by stat and by lstat, but not by fstatat.
* tests/test-statat.c: Disable deprecated-declarations warnings.

ChangeLog
NEWS
lib/fchownat.c
lib/openat.h
lib/renameatu.c
lib/unlinkat.c
modules/fchownat
modules/renameatu
modules/statat
modules/unlinkat
tests/test-statat.c

index 58873a176271a919dcb52353ef29f3b28626ee35..294f6286f3e4adb021269492041804b369f63fc2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2022-03-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       statat: now obsolete
+       * lib/openat.h (statat, lstatat): Now deprecated.
+       All uses removed, and replaced with fstatat.
+       * modules/statat: Mark as obsolete, because it’s confusing:
+       it’s not clear whether it should use AT_NO_AUTOMOUNT,
+       which is implied by stat and by lstat, but not by fstatat.
+       * tests/test-statat.c: Disable deprecated-declarations warnings.
+
        fts: be consistent about AT_NO_AUTOMOUNT
        * lib/fts.c (fts_stat): Use fstatat with AT_NO_AUTOMOUNT
        consistently, instead of sometimes using stat (which implies
diff --git a/NEWS b/NEWS
index c13a115adab72bed48b8762c311e40ce6a4c447b..8f90d8e9589783755c20b7760023df6ed4a7b2f8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -66,6 +66,9 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2022-03-09  statat          This module is deprecated.  Use fstatat instead,
+                            to specify whether you want AT_NO_AUTOMOUNT.
+
 2022-01-05  stack           This module now uses idx_t instead of size_t
                             for indexes and counts.
 
index c0d97db98b9d0c2b37ae4b50c60bac4f98179642..ff368d356da8a32b630e9b5db112e41ccf6ef42d 100644 (file)
@@ -103,7 +103,7 @@ rpl_fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag)
     struct stat st;
     if (len && file[len - 1] == '/')
       {
-        if (statat (fd, file, &st))
+        if (fstatat (fd, file, &st, 0))
           return -1;
         if (flag == AT_SYMLINK_NOFOLLOW)
           return fchownat (fd, file, owner, group, 0);
index 5c8ff90b804ce09471888bc6a84b7948f2a40cbf..56919ef8dc47fc16f8df12bc2b75d7e45b7d0b89 100644 (file)
@@ -98,12 +98,14 @@ lchmodat (int fd, char const *file, mode_t mode)
 #  define STATAT_INLINE _GL_INLINE
 # endif
 
+_GL_ATTRIBUTE_DEPRECATED
 STATAT_INLINE int
 statat (int fd, char const *name, struct stat *st)
 {
   return fstatat (fd, name, st, 0);
 }
 
+_GL_ATTRIBUTE_DEPRECATED
 STATAT_INLINE int
 lstatat (int fd, char const *name, struct stat *st)
 {
index 0eb33ab6fdafce8e914825d328d184ebee515d39..b4e317d6e5663c86a93f0062a082b7bd86cfc4fb 100644 (file)
@@ -133,12 +133,13 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
       break;
 
     case RENAME_NOREPLACE:
-      /* This has a race between the call to lstatat and the calls to
-         renameat below.  This lstatat is needed even if RENAME_EXCL
+      /* This has a race between the call to fstatat and the calls to
+         renameat below.  This fstatat is needed even if RENAME_EXCL
          is defined, because RENAME_EXCL is buggy on macOS 11.2:
          renameatx_np (fd, "X", fd, "X", RENAME_EXCL) incorrectly
          succeeds when X exists.  */
-      if (lstatat (fd2, dst, &dst_st) == 0 || errno == EOVERFLOW)
+      if (fstatat (fd2, dst, &dst_st, AT_SYMLINK_NOFOLLOW) == 0
+          || errno == EOVERFLOW)
         return errno_fail (EEXIST);
       if (errno != ENOENT)
         return -1;
@@ -164,14 +165,14 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
      the source does not exist, or if the destination cannot be turned
      into a directory, give up now.  Otherwise, strip trailing slashes
      before calling rename.  */
-  if (lstatat (fd1, src, &src_st))
+  if (fstatat (fd1, src, &src_st, AT_SYMLINK_NOFOLLOW))
     return -1;
   if (dst_found_nonexistent)
     {
       if (!S_ISDIR (src_st.st_mode))
         return errno_fail (ENOENT);
     }
-  else if (lstatat (fd2, dst, &dst_st))
+  else if (fstatat (fd2, dst, &dst_st, AT_SYMLINK_NOFOLLOW))
     {
       if (errno != ENOENT || !S_ISDIR (src_st.st_mode))
         return -1;
@@ -196,7 +197,7 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
           goto out;
         }
       strip_trailing_slashes (src_temp);
-      if (lstatat (fd1, src_temp, &src_st))
+      if (fstatat (fd1, src_temp, &src_st, AT_SYMLINK_NOFOLLOW))
         {
           rename_errno = errno;
           goto out;
@@ -213,7 +214,7 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
           goto out;
         }
       strip_trailing_slashes (dst_temp);
-      if (lstatat (fd2, dst_temp, &dst_st))
+      if (fstatat (fd2, dst_temp, &dst_st, AT_SYMLINK_NOFOLLOW))
         {
           if (errno != ENOENT)
             {
index eae60074d45a3c33240054f6c8552c5d2d990a34..c9ff3ab2f18c7fdf0dd831036770d7e9a4b55c8e 100644 (file)
@@ -58,7 +58,7 @@ rpl_unlinkat (int fd, char const *name, int flag)
          rule of letting unlink("link-to-dir/") attempt to unlink a
          directory.  */
       struct stat st;
-      result = lstatat (fd, name, &st);
+      result = fstatat (fd, name, &st, AT_SYMLINK_NOFOLLOW);
       if (result == 0 || errno == EOVERFLOW)
         {
           /* Trailing NUL will overwrite the trailing slash.  */
@@ -71,7 +71,8 @@ rpl_unlinkat (int fd, char const *name, int flag)
           memcpy (short_name, name, len);
           while (len && ISSLASH (short_name[len - 1]))
             short_name[--len] = '\0';
-          if (len && (lstatat (fd, short_name, &st) || S_ISLNK (st.st_mode)))
+          if (len && (fstatat (fd, short_name, &st, AT_SYMLINK_NOFOLLOW)
+                      || S_ISLNK (st.st_mode)))
             {
               free (short_name);
               errno = EPERM;
index ea2f2e678c94a9179be894cb8c556e08514faf91..49c4b18096942ee675bde4a33510e7fd9b5acc82 100644 (file)
@@ -19,7 +19,6 @@ lchown          [test $HAVE_FCHOWNAT = 0 || test $REPLACE_FCHOWNAT = 1]
 openat-die      [test $HAVE_FCHOWNAT = 0 || test $REPLACE_FCHOWNAT = 1]
 openat-h        [test $HAVE_FCHOWNAT = 0 || test $REPLACE_FCHOWNAT = 1]
 save-cwd        [test $HAVE_FCHOWNAT = 0 || test $REPLACE_FCHOWNAT = 1]
-statat          [test $REPLACE_FCHOWNAT = 1]
 
 configure.ac:
 gl_FUNC_FCHOWNAT
index 5ce8e47587da08a7d7fc3257e3eac66616d9d351..e0c1ce3176bade19f305b828dbf7b5fcc9a7c115 100644 (file)
@@ -13,7 +13,6 @@ extensions
 fcntl-h
 filenamecat-lgpl [test $HAVE_RENAMEAT = 0 || test $REPLACE_RENAMEAT = 1]
 openat-h         [test $HAVE_RENAMEAT = 0 || test $REPLACE_RENAMEAT = 1]
-statat           [test $REPLACE_RENAMEAT = 1]
 stdbool          [test $REPLACE_RENAMEAT = 1]
 at-internal      [test $HAVE_RENAMEAT = 0]
 filename         [test $HAVE_RENAMEAT = 0]
index 074d342bd8d1c73a3b68abd693617385bdcf5f94..bf274e054dfe7f6f4645ffb2ae73117f9d06dde6 100644 (file)
@@ -1,6 +1,13 @@
 Description:
 statat() and lstatat() functions: Return info about a file at a directory.
 
+Status:
+obsolete
+
+Notice:
+This module is obsolete.  Please use fstatat instead, and decide
+whether you want AT_NO_AUTOMOUNT in each fstatat call.
+
 Files:
 lib/statat.c
 
index 0efc1cc1b223f257aad2adcc0dfa0f77e2ac8cac..ed11c1e97118b960e831cdd9e88ba1a13cb5d75b 100644 (file)
@@ -13,7 +13,6 @@ extensions
 fcntl-h         [test $HAVE_UNLINKAT = 0 || test $REPLACE_UNLINKAT = 1]
 openat-h        [test $HAVE_UNLINKAT = 0 || test $REPLACE_UNLINKAT = 1]
 sys_stat        [test $HAVE_UNLINKAT = 0 || test $REPLACE_UNLINKAT = 1]
-statat          [test $REPLACE_UNLINKAT = 1]
 at-internal     [test $HAVE_UNLINKAT = 0]
 errno           [test $HAVE_UNLINKAT = 0]
 fchdir          [test $HAVE_UNLINKAT = 0]
index a573604e1c197fbea60e4d1470fc3d72565756ac..f46c3f58b51b879a98335dc504dfefbed9a38e32 100644 (file)
 
 #include "openat.h"
 
+#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__)
+# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 #include "signature.h"
 SIGNATURE_CHECK (statat, int, (int, char const *, struct stat *));
 SIGNATURE_CHECK (lstatat, int, (int, char const *, struct stat *));