fix the use of uninitialized value in regcomp
[musl.git] / src / stat / fchmodat.c
blobd94667aed5e1a4aa1e924bd89a8ba3aa3ec6aa16
1 #include <sys/stat.h>
2 #include <fcntl.h>
3 #include <errno.h>
4 #include "syscall.h"
6 void __procfdname(char *, unsigned);
8 int fchmodat(int fd, const char *path, mode_t mode, int flag)
10 if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag);
12 if (flag != AT_SYMLINK_NOFOLLOW)
13 return __syscall_ret(-EINVAL);
15 struct stat st;
16 int ret, fd2;
17 char proc[15+3*sizeof(int)];
19 if ((ret = __syscall(SYS_fstatat, fd, path, &st, flag)))
20 return __syscall_ret(ret);
21 if (S_ISLNK(st.st_mode))
22 return __syscall_ret(-EOPNOTSUPP);
24 if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY|O_CLOEXEC)) < 0) {
25 if (fd2 == -ELOOP)
26 return __syscall_ret(-EOPNOTSUPP);
27 return __syscall_ret(fd2);
30 __procfdname(proc, fd2);
31 ret = __syscall(SYS_fstatat, AT_FDCWD, proc, &st, 0);
32 if (!ret) {
33 if (S_ISLNK(st.st_mode)) ret = -EOPNOTSUPP;
34 else ret = __syscall(SYS_fchmodat, AT_FDCWD, proc, mode);
37 __syscall(SYS_close, fd2);
38 return __syscall_ret(ret);