diff options
author | Markos Chandras <markos.chandras@imgtec.com> | 2012-10-10 16:42:37 +0100 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2013-02-20 13:45:10 +0100 |
commit | 90accddebef0cf967e67c9d2412082a361d9f2bd (patch) | |
tree | 74c100d8d2fa61e759cef5a384e21df7cd1ccb9a /libc/sysdeps/linux/common/dup2.c | |
parent | ad68946e285307bf81fe0433ef952fb5386777ec (diff) |
dup2: Use dup3 if arch does not have the dup2 syscall
Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc/sysdeps/linux/common/dup2.c')
-rw-r--r-- | libc/sysdeps/linux/common/dup2.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/common/dup2.c b/libc/sysdeps/linux/common/dup2.c index 006f06b69..98ac4e305 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 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) |