9 int fcntl(int fd, int cmd, ...)
14 arg = va_arg(ap, long);
16 if (cmd == F_SETFL) arg |= O_LARGEFILE;
17 if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, arg);
18 if (cmd == F_GETOWN) {
20 int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex);
21 if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, arg);
22 if (ret) return __syscall_ret(ret);
23 return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid;
25 if (cmd == F_DUPFD_CLOEXEC) {
26 int ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, arg);
29 __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
30 return __syscall_ret(ret);
32 ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, 0);
34 if (ret >= 0) __syscall(SYS_close, ret);
35 return __syscall_ret(-EINVAL);
37 ret = __syscall(SYS_fcntl, fd, F_DUPFD, arg);
38 if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
39 return __syscall_ret(ret);
41 return syscall(SYS_fcntl, fd, cmd, arg);