summaryrefslogtreecommitdiff
path: root/src/unistd
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-08-14 19:21:41 -0400
committerJakob Kaivo <jkk@ung.org>2020-08-14 19:21:41 -0400
commitc2930803f1f379be7cabbd9e784dc9e07ac2633b (patch)
treec51f430ee18e0260af1233f38316906f422be9a4 /src/unistd
parent3c56463d85bfbf3b249aaa41791eec521b86b230 (diff)
implement as system call so the kernel can provide atomicity and assign the right numbers
Diffstat (limited to 'src/unistd')
-rw-r--r--src/unistd/dup2.c19
1 files changed, 3 insertions, 16 deletions
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)
*/