fcntl_h.m4 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Configure fcntl.h.
  2. dnl Copyright (C) 2006, 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.
  6. dnl Written by Paul Eggert.
  7. AC_DEFUN([gl_FCNTL_H],
  8. [
  9. AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
  10. dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
  11. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  12. AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
  13. [AC_RUN_IFELSE(
  14. [AC_LANG_PROGRAM(
  15. [[#include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <unistd.h>
  18. #include <fcntl.h>
  19. #ifndef O_NOATIME
  20. #define O_NOATIME 0
  21. #endif
  22. #ifndef O_NOFOLLOW
  23. #define O_NOFOLLOW 0
  24. #endif
  25. static int const constants[] =
  26. {
  27. O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
  28. O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
  29. };
  30. ]],
  31. [[
  32. int status = !constants;
  33. {
  34. static char const sym[] = "conftest.sym";
  35. if (symlink (".", sym) != 0
  36. || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0)
  37. status |= 32;
  38. }
  39. {
  40. static char const file[] = "confdefs.h";
  41. int fd = open (file, O_RDONLY | O_NOATIME);
  42. char c;
  43. struct stat st0, st1;
  44. if (fd < 0
  45. || fstat (fd, &st0) != 0
  46. || sleep (1) != 0
  47. || read (fd, &c, 1) != 1
  48. || close (fd) != 0
  49. || stat (file, &st1) != 0
  50. || st0.st_atime != st1.st_atime)
  51. status |= 64;
  52. }
  53. return status;]])],
  54. [gl_cv_header_working_fcntl_h=yes],
  55. [case $? in #(
  56. 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
  57. 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
  58. 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
  59. *) gl_cv_header_working_fcntl_h='no';;
  60. esac],
  61. [gl_cv_header_working_fcntl_h=cross-compiling])])
  62. case $gl_cv_header_working_fcntl_h in #(
  63. *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
  64. *) ac_val=1;;
  65. esac
  66. AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
  67. [Define to 1 if O_NOATIME works.])
  68. case $gl_cv_header_working_fcntl_h in #(
  69. *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
  70. *) ac_val=1;;
  71. esac
  72. AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
  73. [Define to 1 if O_NOFOLLOW works.])
  74. gl_CHECK_NEXT_HEADERS([fcntl.h])
  75. FCNTL_H='fcntl.h'
  76. AC_SUBST([FCNTL_H])
  77. ])
  78. AC_DEFUN([gl_FCNTL_MODULE_INDICATOR],
  79. [
  80. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  81. AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
  82. GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
  83. ])
  84. AC_DEFUN([gl_FCNTL_H_DEFAULTS],
  85. [
  86. GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN])
  87. dnl Assume proper GNU behavior unless another module says otherwise.
  88. REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN])
  89. ])