summaryrefslogtreecommitdiff
path: root/src/stat
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2022-04-28 02:02:38 -0400
committerRich Felker <dalias@aerifal.cx>2022-05-01 23:25:21 -0400
commit7edbcbeb76cb46381c34e2c0491dcc459cd5fa46 (patch)
tree0d0ea2fd940b8cda26e17957ac8c0e8af243c560 /src/stat
parent9a9374955517bf731f11fd2c4a071b3cc1120526 (diff)
downloadmusl-7edbcbeb76cb46381c34e2c0491dcc459cd5fa46.tar.gz
musl-7edbcbeb76cb46381c34e2c0491dcc459cd5fa46.tar.bz2
musl-7edbcbeb76cb46381c34e2c0491dcc459cd5fa46.tar.xz
musl-7edbcbeb76cb46381c34e2c0491dcc459cd5fa46.zip
drop direct use of stat syscalls in fchmodat
instead, use the fstatat/stat functions, so that the logic for which syscalls are present and usable is all in fstatat. this results in a slight increase in cost for old kernels on 32-bit archs: now statx will be attempted first rather than just using the legacy time32 syscalls, despite us not caring about timestamps. however, it's not even clear that the legacy syscalls *should* succeed if the timestamps are out of range; arguably they should fail with EOVERFLOW. as such, paying a small cost here on old kernels seems well-motivated. with this change, fchmodat itself is no longer blocking ports to new archs that lack the legacy syscalls.
Diffstat (limited to 'src/stat')
-rw-r--r--src/stat/fchmodat.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/stat/fchmodat.c b/src/stat/fchmodat.c
index 4ee00b0a..bc581050 100644
--- a/src/stat/fchmodat.c
+++ b/src/stat/fchmodat.c
@@ -2,7 +2,6 @@
#include <fcntl.h>
#include <errno.h>
#include "syscall.h"
-#include "kstat.h"
int fchmodat(int fd, const char *path, mode_t mode, int flag)
{
@@ -11,12 +10,12 @@ int fchmodat(int fd, const char *path, mode_t mode, int flag)
if (flag != AT_SYMLINK_NOFOLLOW)
return __syscall_ret(-EINVAL);
- struct kstat st;
+ struct stat st;
int ret, fd2;
char proc[15+3*sizeof(int)];
- if ((ret = __syscall(SYS_fstatat, fd, path, &st, flag)))
- return __syscall_ret(ret);
+ if (fstatat(fd, path, &st, flag))
+ return -1;
if (S_ISLNK(st.st_mode))
return __syscall_ret(-EOPNOTSUPP);
@@ -27,12 +26,12 @@ int fchmodat(int fd, const char *path, mode_t mode, int flag)
}
__procfdname(proc, fd2);
- ret = __syscall(SYS_fstatat, AT_FDCWD, proc, &st, 0);
+ ret = stat(proc, &st);
if (!ret) {
- if (S_ISLNK(st.st_mode)) ret = -EOPNOTSUPP;
- else ret = __syscall(SYS_fchmodat, AT_FDCWD, proc, mode);
+ if (S_ISLNK(st.st_mode)) ret = __syscall_ret(-EOPNOTSUPP);
+ else ret = syscall(SYS_fchmodat, AT_FDCWD, proc, mode);
}
__syscall(SYS_close, fd2);
- return __syscall_ret(ret);
+ return ret;
}