Hi Collin, > Currently dup3 is replaced unconditionally. I made this change in a > NetBSD virtual machine and the test program passes: > > $ git diff . > diff --git a/lib/dup3.c b/lib/dup3.c > index a810d3be19..7674f042a4 100644 > --- a/lib/dup3.c > +++ b/lib/dup3.c > @@ -34,6 +34,15 @@ dup3 (int oldfd, int newfd, int flags) > /* Avoid a cygwin crasher. */ > setdtablesize (newfd + 1); > # endif > + > +#ifdef __NetBSD__ > + if (newfd == oldfd) > + { > + errno = EINVAL; > + return -1; > + } > +#endif > + > /* Try the system call first, if it exists. (We may be running with a > glibc > that has the function but with an older kernel that lacks it.) */ > {
An interesting approach. But I think this added code comes too early: In case of oldfd == newfd && newfd < 0, it would fail with EINVAL instead of EBADF. How about trying the system call first, and test for newfd == oldfd only if that system call succeeds? Bruno