This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
PATCH: linux-generic dup2 behaviour
- From: Linas Vepstas <linasvepstas at gmail dot com>
- To: Chris Metcalf <cmetcalf at tilera dot com>
- Cc: Arnd Bergmann <arnd at arndb dot de>, GLIBC Devel <libc-alpha at sourceware dot org>, libc-ports at sourceware dot org
- Date: Tue, 13 Sep 2011 16:10:54 -0500
- Subject: PATCH: linux-generic dup2 behaviour
- Reply-to: linasvepstas at gmail dot com
Chris, here's another:
man dup2 states that:
If oldfd is a valid file descriptor, and newfd has the same value as
oldfd, then dup2() does nothing, and returns newfd.
while the linux kernel does this in fs/fcntl.c:
if (unlikely(oldfd == newfd)) return -EINVAL;
Which I presume is correct for dup3.
Thus, dup2 needs fixing. Note that m4 test suite catches this.
---
sysdeps/unix/sysv/linux/generic/dup2.c | 2 ++
1 file changed, 2 insertions(+)
Index: glibc-2.14/sysdeps/unix/sysv/linux/generic/dup2.c
===================================================================
--- glibc-2.14.orig/sysdeps/unix/sysv/linux/generic/dup2.c 2011-09-13
15:39:03.000000000 -0500
+++ glibc-2.14/sysdeps/unix/sysv/linux/generic/dup2.c 2011-09-13
15:40:09.000000000 -0500
@@ -26,6 +26,8 @@
int
__dup2 (int fd, int fd2)
{
+ /* if fd's are equal, preserve documented dup2 response */
+ if (fd == fd2) return fd;
return INLINE_SYSCALL(dup3, 3, fd, fd2, 0);
}
libc_hidden_def (__dup2)