X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstat%2Ffchmodat.c;h=4ee00b0a3ed18cb1ce15c62ff4ce517c7bbf9ece;hb=51f4f8c512d682fe0c1a7a891909e75f416f20f6;hp=61d3206553e6770d18ae1b53bda2f071fb5e7768;hpb=aa398f56fa398f2202b04e82c67f822f3233786f;p=musl diff --git a/src/stat/fchmodat.c b/src/stat/fchmodat.c index 61d32065..4ee00b0a 100644 --- a/src/stat/fchmodat.c +++ b/src/stat/fchmodat.c @@ -1,7 +1,38 @@ #include +#include +#include #include "syscall.h" +#include "kstat.h" int fchmodat(int fd, const char *path, mode_t mode, int flag) { - return syscall(SYS_fchmodat, fd, path, mode, flag); + if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag); + + if (flag != AT_SYMLINK_NOFOLLOW) + return __syscall_ret(-EINVAL); + + struct kstat st; + int ret, fd2; + char proc[15+3*sizeof(int)]; + + if ((ret = __syscall(SYS_fstatat, fd, path, &st, flag))) + return __syscall_ret(ret); + 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|O_CLOEXEC)) < 0) { + if (fd2 == -ELOOP) + return __syscall_ret(-EOPNOTSUPP); + return __syscall_ret(fd2); + } + + __procfdname(proc, fd2); + 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); }