mkstemp.m4 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #serial 23
  2. # Copyright (C) 2001, 2003-2007, 2009-2014 Free Software Foundation, Inc.
  3. # This file is free software; the Free Software Foundation
  4. # gives unlimited permission to copy and/or distribute it,
  5. # with or without modifications, as long as this notice is preserved.
  6. # On some hosts (e.g., HP-UX 10.20, SunOS 4.1.4, Solaris 2.5.1), mkstemp has a
  7. # silly limit that it can create no more than 26 files from a given template.
  8. # Other systems lack mkstemp altogether.
  9. # On OSF1/Tru64 V4.0F, the system-provided mkstemp function can create
  10. # only 32 files per process.
  11. # On some hosts, mkstemp creates files with mode 0666, which is a security
  12. # problem and a violation of POSIX 2008.
  13. # On systems like the above, arrange to use the replacement function.
  14. AC_DEFUN([gl_FUNC_MKSTEMP],
  15. [
  16. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  17. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  18. AC_CHECK_FUNCS_ONCE([mkstemp])
  19. if test $ac_cv_func_mkstemp = yes; then
  20. AC_CACHE_CHECK([for working mkstemp],
  21. [gl_cv_func_working_mkstemp],
  22. [
  23. mkdir conftest.mkstemp
  24. AC_RUN_IFELSE(
  25. [AC_LANG_PROGRAM(
  26. [AC_INCLUDES_DEFAULT],
  27. [[int result = 0;
  28. int i;
  29. off_t large = (off_t) 4294967295u;
  30. if (large < 0)
  31. large = 2147483647;
  32. umask (0);
  33. for (i = 0; i < 70; i++)
  34. {
  35. char templ[] = "conftest.mkstemp/coXXXXXX";
  36. int (*mkstemp_function) (char *) = mkstemp;
  37. int fd = mkstemp_function (templ);
  38. if (fd < 0)
  39. result |= 1;
  40. else
  41. {
  42. struct stat st;
  43. if (lseek (fd, large, SEEK_SET) != large)
  44. result |= 2;
  45. if (fstat (fd, &st) < 0)
  46. result |= 4;
  47. else if (st.st_mode & 0077)
  48. result |= 8;
  49. if (close (fd))
  50. result |= 16;
  51. }
  52. }
  53. return result;]])],
  54. [gl_cv_func_working_mkstemp=yes],
  55. [gl_cv_func_working_mkstemp=no],
  56. [case "$host_os" in
  57. # Guess yes on glibc systems.
  58. *-gnu*) gl_cv_func_working_mkstemp="guessing yes" ;;
  59. # If we don't know, assume the worst.
  60. *) gl_cv_func_working_mkstemp="guessing no" ;;
  61. esac
  62. ])
  63. rm -rf conftest.mkstemp
  64. ])
  65. case "$gl_cv_func_working_mkstemp" in
  66. *yes) ;;
  67. *)
  68. REPLACE_MKSTEMP=1
  69. ;;
  70. esac
  71. else
  72. HAVE_MKSTEMP=0
  73. fi
  74. ])
  75. # Prerequisites of lib/mkstemp.c.
  76. AC_DEFUN([gl_PREREQ_MKSTEMP],
  77. [
  78. ])