From c2930803f1f379be7cabbd9e784dc9e07ac2633b Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 14 Aug 2020 19:21:41 -0400 Subject: implement as system call so the kernel can provide atomicity and assign the right numbers --- src/unistd/dup2.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/unistd/dup2.c b/src/unistd/dup2.c index 2755fbc7..ba709a3c 100644 --- a/src/unistd/dup2.c +++ b/src/unistd/dup2.c @@ -4,26 +4,13 @@ #include "fcntl.h" #include "limits.h" #include "errno.h" +#include "_syscall.h" int dup2(int fildes, int fildes2) { - if (fildes2 < 0 || fildes2 >= _POSIX_OPEN_MAX) { - errno = EBADF; - return -1; - } - - if (fildes == fildes2) { - return fildes2; - } - - if (fcntl(fildes, F_GETFD) == -1) { - errno = EBADF; - return -1; - } - - close(fildes2); - return fcntl(fildes, F_DUPFD, fildes2); + SYSCALL(dup2, int, -1, fildes, fildes2, 0, 0, 0, 0); } + /* POSIX(1) */ -- cgit v1.2.1