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>