7 int fchmodat(int fd, const char *path, mode_t mode, int flag)
9 if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag);
11 if (flag != AT_SYMLINK_NOFOLLOW)
12 return __syscall_ret(-EINVAL);
16 char proc[15+3*sizeof(int)];
18 if ((ret = __syscall(SYS_fstatat, fd, path, &st, flag)))
19 return __syscall_ret(ret);
20 if (S_ISLNK(st.st_mode))
21 return __syscall_ret(-EOPNOTSUPP);
23 if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY)) < 0) {
25 return __syscall_ret(-EOPNOTSUPP);
26 return __syscall_ret(fd2);
29 snprintf(proc, sizeof proc, "/proc/self/fd/%d", fd2);
30 if (!(ret = __syscall(SYS_stat, proc, &st)) && !S_ISLNK(st.st_mode))
31 ret = __syscall(SYS_chmod, proc, mode);
33 __syscall(SYS_close, fd2);
34 return __syscall_ret(ret);