[[PATCH v2] 3/4] support kernels without __ARCH_WANT_SYSCALL_NO_FLAGS
Mark Salter
msalter at redhat.com
Fri May 4 12:52:19 UTC 2012
Signed-off-by: Mark Salter <msalter at redhat.com>
---
libc/sysdeps/linux/common/dup2.c | 22 ++++++++++++++++++++++
libc/sysdeps/linux/common/pipe.c | 7 +++++++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/libc/sysdeps/linux/common/dup2.c b/libc/sysdeps/linux/common/dup2.c
index 006f06b..792e81e 100644
--- a/libc/sysdeps/linux/common/dup2.c
+++ b/libc/sysdeps/linux/common/dup2.c
@@ -11,5 +11,27 @@
#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) {
+ int err;
+#ifdef __NR_fcntl64
+ err = INLINE_SYSCALL(fcntl64, 3, fd, F_GETFL, 0);
+#else
+ err = INLINE_SYSCALL(fcntl, 3, fd, F_GETFL, 0);
+#endif
+ return err < 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..bc316f8 100644
--- a/libc/sysdeps/linux/common/pipe.c
+++ b/libc/sysdeps/linux/common/pipe.c
@@ -11,5 +11,12 @@
#include <unistd.h>
+#if defined(__NR_pipe)
_syscall1(int, pipe, int *, filedes)
+#elif defined(__NR_pipe2)
+int pipe(int filedes[2])
+{
+ return INLINE_SYSCALL(pipe2, 2, filedes, 0);
+}
+#endif
libc_hidden_def(pipe)
--
1.7.9.1
More information about the uClibc
mailing list