dup2: fix logic bugs
authorEric Blake <ebb9@byu.net>
Tue, 8 Dec 2009 04:08:17 +0000 (21:08 -0700)
committerEric Blake <ebb9@byu.net>
Tue, 8 Dec 2009 13:29:15 +0000 (06:29 -0700)
commit21a0a9e3ef07b457b04d483f8dd216bbdf06e860
treed34e73d0c5ff367e821482a3d67853ed1e72112f
parent67ac31ed5b8a602032d034bd91022ba329e6485f
dup2: fix logic bugs

If the platform has dup2, don't register with fchdir if the
destination was -1.

If the platform lacks dup2 (are there any these days?), then don't
close the destination unless the source is valid, make sure errno
is correct, and only register with fchdir on fcntl (since dup is
already overridden to do a registration).

* lib/dup2.c (dup2): Fix logic bugs.  Use HAVE_DUP2 rather than
REPLACE_DUP2 to decide when rpl_dup2 is needed.
* m4/dup2.m4 (gl_REPLACE_DUP2): Only define REPLACE_DUP2 when dup2
exists.
(gl_FUNC_DUP2): Drop unneeded AC_SUBST.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/dup2.c
m4/dup2.m4