Put more information about failed tests into the test return codes.
[gnulib.git] / m4 / dup2.m4
1 #serial 11
2 dnl Copyright (C) 2002, 2005, 2007, 2009-2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_DUP2],
8 [
9   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST])
11   AC_CHECK_FUNCS_ONCE([dup2])
12   if test $ac_cv_func_dup2 = no; then
13     HAVE_DUP2=0
14     AC_LIBOBJ([dup2])
15   else
16     AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
17       [AC_RUN_IFELSE([
18          AC_LANG_PROGRAM([[#include <unistd.h>
19 #include <errno.h>]],
20            [int result = 0;
21             if (dup2 (1, 1) == 0)
22               result |= 1;
23             close (0);
24             if (dup2 (0, 0) != -1)
25               result |= 2;
26             /* Many gnulib modules require POSIX conformance of EBADF.  */
27             if (dup2 (1, 1000000) == -1 && errno != EBADF)
28               result |= 4;
29             return result;
30            ])
31         ],
32         [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
33         [case "$host_os" in
34            mingw*) # on this platform, dup2 always returns 0 for success
35              gl_cv_func_dup2_works=no;;
36            cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
37              gl_cv_func_dup2_works=no;;
38            linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a
39                    # closed fd may yield -EBADF instead of -1 / errno=EBADF.
40              gl_cv_func_dup2_works=no;;
41            freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF.
42              gl_cv_func_dup2_works=no;;
43            *) gl_cv_func_dup2_works=yes;;
44          esac])
45       ])
46     if test "$gl_cv_func_dup2_works" = no; then
47       gl_REPLACE_DUP2
48     fi
49   fi
50 ])
51
52 AC_DEFUN([gl_REPLACE_DUP2],
53 [
54   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
55   if test $ac_cv_func_dup2 = yes; then
56     REPLACE_DUP2=1
57   fi
58   AC_LIBOBJ([dup2])
59 ])