From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/unistd/dup2.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/unistd/dup2.c (limited to 'src/unistd/dup2.c') diff --git a/src/unistd/dup2.c b/src/unistd/dup2.c new file mode 100644 index 0000000..8f43c6d --- /dev/null +++ b/src/unistd/dup2.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include "syscall.h" + +int dup2(int old, int new) +{ + int r; +#ifdef SYS_dup2 + while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); +#else + if (old==new) { + r = __syscall(SYS_fcntl, old, F_GETFD); + if (r >= 0) return old; + } else { + while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY); + } +#endif + return __syscall_ret(r); +} -- cgit v1.2.3