2 dnl Copyright (C) 2002, 2005, 2007, 2009 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.
7 AC_DEFUN([gl_FUNC_DUP2],
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
16 AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
18 AC_LANG_PROGRAM([[#include <unistd.h>]],
19 [if (dup2 (1, 1) == 0)
22 if (dup2 (0, 0) != -1)
27 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
29 mingw*) # on this platform, dup2 always returns 0 for success
30 gl_cv_func_dup2_works=no;;
31 cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
32 gl_cv_func_dup2_works=no;;
33 linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a
34 # closed fd may yield -EBADF instead of -1 / errno=EBADF.
35 gl_cv_func_dup2_works=no;;
36 *) gl_cv_func_dup2_works=yes;;
39 if test "$gl_cv_func_dup2_works" = no; then
43 AC_DEFINE_UNQUOTED([REPLACE_DUP2], [$REPLACE_DUP2],
44 [Define to 1 if dup2 returns 0 instead of the target fd.])
47 AC_DEFUN([gl_REPLACE_DUP2],
49 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])