fix dup3 ignoring all flags but O_CLOEXEC on archs with SYS_dup2 syscall
[musl] / src / unistd / dup3.c
index f919f79..1e7dc3e 100644 (file)
@@ -9,9 +9,10 @@ int __dup3(int old, int new, int flags)
        int r;
 #ifdef SYS_dup2
        if (old==new) return __syscall_ret(-EINVAL);
-       if (flags & O_CLOEXEC) {
+       if (flags) {
                while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
                if (r!=-ENOSYS) return __syscall_ret(r);
+               if (flags & ~O_CLOEXEC) return __syscall_ret(-EINVAL);
        }
        while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
        if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC);