8 int fcntl(int fd, int cmd, ...)
13 arg = va_arg(ap, long);
15 if (cmd == F_SETFL) arg |= O_LARGEFILE;
16 if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
17 if (cmd == F_GETOWN) {
19 int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex);
20 if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, (void *)arg);
21 if (ret) return __syscall_ret(ret);
22 return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid;
24 if (cmd == F_DUPFD_CLOEXEC) {
25 int ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, arg);
28 __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
29 return __syscall_ret(ret);
31 ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, 0);
33 if (ret >= 0) __syscall(SYS_close, ret);
34 return __syscall_ret(-EINVAL);
36 ret = __syscall(SYS_fcntl, fd, F_DUPFD, arg);
37 if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
38 return __syscall_ret(ret);
46 return syscall(SYS_fcntl, fd, cmd, (void *)arg);
48 return syscall(SYS_fcntl, fd, cmd, arg);