summaryrefslogtreecommitdiff
path: root/m4/dup2.m4
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-07-21 06:48:26 -0600
committerEric Blake <ebb9@byu.net>2009-07-21 07:08:06 -0600
commitddd625ddd088a87d5598256d09b2036c63063386 (patch)
tree57eb630aa1bdf55c46b7b1008aa59619e49d67d4 /m4/dup2.m4
parent77ef628397e3c8951051305e9601a7800c895b73 (diff)
downloadgnulib-ddd625ddd088a87d5598256d09b2036c63063386.tar.gz
dup2: work around mingw and cygwin 1.5 bug
* m4/dup2.m4 (gl_FUNC_DUP2): Detect mingw bug. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add witness. * modules/unistd (Makefile.am): Substitute it. * lib/unistd.in.h (dup2): Declare the replacement. * lib/dup2.c (dup2) [REPLACE_DUP2]: Implement it. * doc/posix-functions/dup2.texi (dup2): Document the bugs. * lib/fchdir.c (rpl_dup2): Don't collide with mingw replacement. * modules/execute (Depends-on): Add dup2. * modules/fseterr (Depends-on): Likewise. * modules/pipe (Depends-on): Likewise. * modules/posix_spawn-internal (Depends-on): Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'm4/dup2.m4')
-rw-r--r--m4/dup2.m424
1 files changed, 22 insertions, 2 deletions
diff --git a/m4/dup2.m4 b/m4/dup2.m4
index 054982359e..2abc74cdc5 100644
--- a/m4/dup2.m4
+++ b/m4/dup2.m4
@@ -1,5 +1,5 @@
-#serial 5
-dnl Copyright (C) 2002, 2005, 2007 Free Software Foundation, Inc.
+#serial 6
+dnl Copyright (C) 2002, 2005, 2007, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -7,9 +7,29 @@ dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_DUP2],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST])
AC_CHECK_FUNCS_ONCE([dup2])
if test $ac_cv_func_dup2 = no; then
HAVE_DUP2=0
AC_LIBOBJ([dup2])
+ else
+ AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
+ [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <unistd.h>
+]], [return 1 - dup2 (1, 1);])],
+ [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
+ [case "$host_os" in
+ mingw*) # on this platform, dup2 always returns 0 for success
+ gl_cv_func_dup2_works=no;;
+ cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
+ gl_cv_func_dup2_works=no;;
+ *) gl_cv_func_dup2_works=yes;;
+ esac])])
+ if test "$gl_cv_func_dup2_works" = no; then
+ REPLACE_DUP2=1
+ AC_LIBOBJ([dup2])
+ fi
fi
+ AC_DEFINE_UNQUOTED([REPLACE_DUP2], [$REPLACE_DUP2],
+ [Define to 1 if dup2 returns 0 instead of the target fd.])
])