mirror of
https://https.git.savannah.gnu.org/git/gnulib.git
synced 2026-09-01 11:16:02 +00:00
faccessat: support "" and NULL file
* lib/faccessat.c (LSTAT_FOLLOWS_SLASHED_SYMLINK): Default to 0. (rpl_faccessat): Don’t mishandle empty string, or null pointer for that matter. Also, do not call fstatat if LSTAT_FOLLOWS_SLASHED_SYMLINK, as there is no need in that case.
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
2026-06-16 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
faccessat: support "" and NULL file
|
||||
* lib/faccessat.c (LSTAT_FOLLOWS_SLASHED_SYMLINK): Default to 0.
|
||||
(rpl_faccessat): Don’t mishandle empty string, or null pointer for
|
||||
that matter. Also, do not call fstatat if
|
||||
LSTAT_FOLLOWS_SLASHED_SYMLINK, as there is no need in that case.
|
||||
|
||||
fcntl-h: glibc now has openat2
|
||||
* m4/fcntl_h.m4 (gl_FCNTL_H_DEFAULTS): HAVE_OPENAT2 is now 1,
|
||||
as glibc 2.43 (2026) supports it.
|
||||
|
||||
+18
-10
@@ -50,24 +50,32 @@ orig_faccessat (int fd, char const *name, int mode, int flag)
|
||||
# define access euidaccess
|
||||
#endif
|
||||
|
||||
#ifndef LSTAT_FOLLOWS_SLASHED_SYMLINK
|
||||
# define LSTAT_FOLLOWS_SLASHED_SYMLINK 0
|
||||
#endif
|
||||
|
||||
#if HAVE_FACCESSAT
|
||||
|
||||
int
|
||||
rpl_faccessat (int fd, char const *file, int mode, int flag)
|
||||
rpl_faccessat (int fd, char const *file, int mode, int flags)
|
||||
{
|
||||
int result = orig_faccessat (fd, file, mode, flag);
|
||||
int result = orig_faccessat (fd, file, mode, flags);
|
||||
|
||||
if (file[strlen (file) - 1] == '/')
|
||||
if (!LSTAT_FOLLOWS_SLASHED_SYMLINK && file)
|
||||
{
|
||||
struct stat st;
|
||||
int ret = fstatat (fd, file, &st, 0);
|
||||
if (ret == 0 && !S_ISDIR (st.st_mode))
|
||||
size_t len = strlen (file);
|
||||
if (len && file[len - 1] == '/')
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
struct stat st;
|
||||
int ret = fstatat (fd, file, &st, 0);
|
||||
if (ret == 0 && !S_ISDIR (st.st_mode))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
if (result == 0)
|
||||
result = ret;
|
||||
}
|
||||
if (result == 0)
|
||||
result = ret;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user