dup2.m4 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #serial 10
  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. AC_DEFUN([gl_FUNC_DUP2],
  7. [
  8. AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
  9. AC_REQUIRE([AC_CANONICAL_HOST])
  10. AC_CHECK_FUNCS_ONCE([dup2])
  11. if test $ac_cv_func_dup2 = no; then
  12. HAVE_DUP2=0
  13. AC_LIBOBJ([dup2])
  14. else
  15. AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
  16. [AC_RUN_IFELSE([
  17. AC_LANG_PROGRAM([[#include <unistd.h>
  18. #include <errno.h>]],
  19. [if (dup2 (1, 1) == 0)
  20. return 1;
  21. close (0);
  22. if (dup2 (0, 0) != -1)
  23. return 2;
  24. /* Many gnulib modules require POSIX conformance of EBADF. */
  25. if (dup2 (1, 1000000) == -1 && errno != EBADF)
  26. return 3;
  27. return 0;
  28. ])
  29. ],
  30. [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
  31. [case "$host_os" in
  32. mingw*) # on this platform, dup2 always returns 0 for success
  33. gl_cv_func_dup2_works=no;;
  34. cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
  35. gl_cv_func_dup2_works=no;;
  36. linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a
  37. # closed fd may yield -EBADF instead of -1 / errno=EBADF.
  38. gl_cv_func_dup2_works=no;;
  39. freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF.
  40. gl_cv_func_dup2_works=no;;
  41. *) gl_cv_func_dup2_works=yes;;
  42. esac])
  43. ])
  44. if test "$gl_cv_func_dup2_works" = no; then
  45. gl_REPLACE_DUP2
  46. fi
  47. fi
  48. ])
  49. AC_DEFUN([gl_REPLACE_DUP2],
  50. [
  51. AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
  52. if test $ac_cv_func_dup2 = yes; then
  53. REPLACE_DUP2=1
  54. fi
  55. AC_LIBOBJ([dup2])
  56. ])