X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Funistd%2Fdup3.c;h=1f7134b3dcbf7ea16390b543f38798c4b33549b0;hp=18f6fccef24fb12fdc83a72958d3423618ae7a1d;hb=892cafff665b44d238e3b664f61ca38dd965cba6;hpb=708c91f4e9be2cfd6d35e71361956e13f3201b85 diff --git a/src/unistd/dup3.c b/src/unistd/dup3.c index 18f6fcce..1f7134b3 100644 --- a/src/unistd/dup3.c +++ b/src/unistd/dup3.c @@ -1,10 +1,21 @@ #define _GNU_SOURCE #include #include +#include #include "syscall.h" +#include "libc.h" -int dup3(int old, int new, int flags) { +int __dup3(int old, int new, int flags) +{ int r; - while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); + if (old==new) return __syscall_ret(-EINVAL); + if (flags & O_CLOEXEC) { + while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); + if (r!=-ENOSYS) return __syscall_ret(r); + } + while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); + if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC); return __syscall_ret(r); } + +weak_alias(__dup3, dup3);