cuserid: support invocation with a null pointer argument
[musl.git] / src / unistd / dup2.c
blob8f43c6ddfe8983e9565d6a14a10f423c9fd55f05
1 #include <unistd.h>
2 #include <errno.h>
3 #include <fcntl.h>
4 #include "syscall.h"
6 int dup2(int old, int new)
8 int r;
9 #ifdef SYS_dup2
10 while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
11 #else
12 if (old==new) {
13 r = __syscall(SYS_fcntl, old, F_GETFD);
14 if (r >= 0) return old;
15 } else {
16 while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY);
18 #endif
19 return __syscall_ret(r);