X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstat%2Ffchmodat.c;h=4ee00b0a3ed18cb1ce15c62ff4ce517c7bbf9ece;hb=043c6e31d9135c27875a1ccb4c0f1638f0170e77;hp=aeb50bc5741aa3740c13f78cc95319ffb7e26207;hpb=c8c0844f7fbcb955848ca84432e5ffcf71f1cef1;p=musl diff --git a/src/stat/fchmodat.c b/src/stat/fchmodat.c index aeb50bc5..4ee00b0a 100644 --- a/src/stat/fchmodat.c +++ b/src/stat/fchmodat.c @@ -1,10 +1,8 @@ #include #include #include -#include #include "syscall.h" - -void __procfdname(char *, unsigned); +#include "kstat.h" int fchmodat(int fd, const char *path, mode_t mode, int flag) { @@ -13,7 +11,7 @@ int fchmodat(int fd, const char *path, mode_t mode, int flag) if (flag != AT_SYMLINK_NOFOLLOW) return __syscall_ret(-EINVAL); - struct stat st; + struct kstat st; int ret, fd2; char proc[15+3*sizeof(int)]; @@ -22,15 +20,18 @@ int fchmodat(int fd, const char *path, mode_t mode, int flag) if (S_ISLNK(st.st_mode)) return __syscall_ret(-EOPNOTSUPP); - if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY)) < 0) { + if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY|O_CLOEXEC)) < 0) { if (fd2 == -ELOOP) return __syscall_ret(-EOPNOTSUPP); return __syscall_ret(fd2); } __procfdname(proc, fd2); - if (!(ret = __syscall(SYS_stat, proc, &st)) && !S_ISLNK(st.st_mode)) - ret = __syscall(SYS_chmod, proc, mode); + ret = __syscall(SYS_fstatat, AT_FDCWD, proc, &st, 0); + if (!ret) { + if (S_ISLNK(st.st_mode)) ret = -EOPNOTSUPP; + else ret = __syscall(SYS_fchmodat, AT_FDCWD, proc, mode); + } __syscall(SYS_close, fd2); return __syscall_ret(ret);