X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstat%2Ffchmodat.c;h=bc581050eeb7072e1bc97ef8b293ba2d750c3fc1;hb=29e4319178cbc2a4e9f058a99ae8098d4b6ac055;hp=61d3206553e6770d18ae1b53bda2f071fb5e7768;hpb=aa398f56fa398f2202b04e82c67f822f3233786f;p=musl diff --git a/src/stat/fchmodat.c b/src/stat/fchmodat.c index 61d32065..bc581050 100644 --- a/src/stat/fchmodat.c +++ b/src/stat/fchmodat.c @@ -1,7 +1,37 @@ #include +#include +#include #include "syscall.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 stat st; + int ret, fd2; + char proc[15+3*sizeof(int)]; + + if (fstatat(fd, path, &st, flag)) + return -1; + 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 = stat(proc, &st); + if (!ret) { + if (S_ISLNK(st.st_mode)) ret = __syscall_ret(-EOPNOTSUPP); + else ret = syscall(SYS_fchmodat, AT_FDCWD, proc, mode); + } + + __syscall(SYS_close, fd2); + return ret; }