From: Markos Chandras <[email protected]>

Signed-off-by: Markos Chandras <[email protected]>
---
 libc/sysdeps/linux/common/dup2.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libc/sysdeps/linux/common/dup2.c b/libc/sysdeps/linux/common/dup2.c
index 006f06b..88856ab 100644
--- a/libc/sysdeps/linux/common/dup2.c
+++ b/libc/sysdeps/linux/common/dup2.c
@@ -9,7 +9,24 @@
 
 #include <sys/syscall.h>
 #include <unistd.h>
+#if defined(__NR_dup3) && !defined(__NR_dup2)
+#include <fcntl.h>
+extern int __libc_fcntl (int fd, int cmd, ...);
+libc_hidden_proto(__libc_fcntl);
 
+int dup2(int old, int newfd)
+{
+       /*
+        * Check if old fd is valid before we try
+        * to ducplicate it. Return it if valid
+        * or EBADF otherwise
+        */
+       if (old == newfd)
+               return __libc_fcntl(old, F_GETFL, 0) < 0 ? -1 : newfd;
 
+       return dup3(old, newfd, 0);
+}
+#else
 _syscall2(int, dup2, int, oldfd, int, newfd)
+#endif
 libc_hidden_def(dup2)
-- 
1.8.0


_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to