1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-09-01 02:34:55 +00:00

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.
This commit is contained in:
Paul Eggert
2022-03-09 13:54:53 -08:00
parent 44f347ce40
commit eea9688d52
11 changed files with 36 additions and 13 deletions
+8
View File
@@ -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 its confusing:
its 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
+3
View File
@@ -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.
+1 -1
View 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);
+2
View 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)
{
+8 -7
View 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)
{
+3 -2
View 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;
-1
View 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
-1
View 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]
+7
View 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
-1
View 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]
+4
View File
@@ -18,6 +18,10 @@
#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 *));