[PATCH] support kernels without __ARCH_WANT_SYSCALL_NO_FLAGS

Mark Salter msalter at redhat.com
Thu Apr 26 14:18:11 UTC 2012


---
 libc/sysdeps/linux/common/dup2.c |   15 +++++++++++++++
 libc/sysdeps/linux/common/pipe.c |   10 ++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/libc/sysdeps/linux/common/dup2.c b/libc/sysdeps/linux/common/dup2.c
index 006f06b..9d4e240 100644
--- a/libc/sysdeps/linux/common/dup2.c
+++ b/libc/sysdeps/linux/common/dup2.c
@@ -11,5 +11,20 @@
 #include <unistd.h>
 
 
+#ifdef __NR_dup2
 _syscall2(int, dup2, int, oldfd, int, newfd)
+#elif defined __NR_dup3
+#include <fcntl.h>
+
+int
+dup2 (int fd, int fd2)
+{
+	/* For the degenerate case, check if the fd is valid (by trying to
+	   get the file status flags) and return it, or else return EBADF.  */
+	if (fd == fd2)
+		return __libc_fcntl(fd, F_GETFL, 0) < 0 ? -1 : fd;
+
+	return INLINE_SYSCALL(dup3, 3, fd, fd2, 0);
+}
+#endif
 libc_hidden_def(dup2)
diff --git a/libc/sysdeps/linux/common/pipe.c b/libc/sysdeps/linux/common/pipe.c
index 8eae27c..c5a5164 100644
--- a/libc/sysdeps/linux/common/pipe.c
+++ b/libc/sysdeps/linux/common/pipe.c
@@ -11,5 +11,15 @@
 #include <unistd.h>
 
 
+#if defined(__NR_pipe)
 _syscall1(int, pipe, int *, filedes)
+#elif defined(__NR_pipe2)
+#define __NR___syscall_pipe2 __NR_pipe2
+static __inline__ _syscall2(int, __syscall_pipe2, int *, filedes,
+		int, flag)
+int pipe(int filedes[2])
+{
+	return __syscall_pipe2(filedes, 0);
+}
+#endif
 libc_hidden_def(pipe)
-- 
1.7.9.1



More information about the uClibc mailing list