X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Funistd%2Fdup3.c;h=f919f79125a624c4d47c1cb50a103f82e0ba576f;hb=613ccabeb0c10ac818e36ef53e09753d23785cbf;hp=18f6fccef24fb12fdc83a72958d3423618ae7a1d;hpb=dc62790deec183697489d5fddea03c82f725e7fd;p=musl diff --git a/src/unistd/dup3.c b/src/unistd/dup3.c index 18f6fcce..f919f791 100644 --- a/src/unistd/dup3.c +++ b/src/unistd/dup3.c @@ -1,10 +1,24 @@ #define _GNU_SOURCE #include #include +#include #include "syscall.h" -int dup3(int old, int new, int flags) { +int __dup3(int old, int new, int flags) +{ int r; +#ifdef SYS_dup2 + 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); +#else while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); +#endif return __syscall_ret(r); } + +weak_alias(__dup3, dup3);