X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstat%2Ffchmodat.c;h=afa6d44b5401da8caec81c3cb78dea9b344b4748;hb=41421d6beb3f17aa8838f7cdaad9cd16b4c451f6;hp=f4f22b2c7f4f271c2402fd5a8ebb250dbc7858e9;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/stat/fchmodat.c b/src/stat/fchmodat.c index f4f22b2c..afa6d44b 100644 --- a/src/stat/fchmodat.c +++ b/src/stat/fchmodat.c @@ -1,7 +1,37 @@ #include +#include +#include #include "syscall.h" +void __procfdname(char *, unsigned); + int fchmodat(int fd, const char *path, mode_t mode, int flag) { - return syscall4(__NR_fchmodat, fd, (long)path, mode, flag); + if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag); + + if (flag != AT_SYMLINK_NOFOLLOW) + return __syscall_ret(-EINVAL); + + 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 (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 == -ELOOP) + return __syscall_ret(-EOPNOTSUPP); + return __syscall_ret(fd2); + } + + __procfdname(proc, fd2); + ret = __syscall(SYS_fstatat, AT_FDCWD, proc, &st, 0); + if (!ret && !S_ISLNK(st.st_mode)) + ret = __syscall(SYS_fchmodat, AT_FDCWD, proc, mode); + + __syscall(SYS_close, fd2); + return __syscall_ret(ret); }