fcntl-o.m4 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # fcntl-o.m4 serial 4
  2. dnl Copyright (C) 2006, 2009-2012 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. # Test whether the flags O_NOATIME and O_NOFOLLOW actually work.
  8. # Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise.
  9. # Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise.
  10. AC_DEFUN([gl_FCNTL_O_FLAGS],
  11. [
  12. dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW.
  13. dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes
  14. dnl AC_GNU_SOURCE.
  15. m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
  16. [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
  17. [AC_REQUIRE([AC_GNU_SOURCE])])
  18. AC_CHECK_HEADERS_ONCE([unistd.h])
  19. AC_CHECK_FUNCS_ONCE([symlink])
  20. AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
  21. [AC_RUN_IFELSE(
  22. [AC_LANG_PROGRAM(
  23. [[#include <sys/types.h>
  24. #include <sys/stat.h>
  25. #if HAVE_UNISTD_H
  26. # include <unistd.h>
  27. #else /* on Windows with MSVC */
  28. # include <io.h>
  29. # include <stdlib.h>
  30. # defined sleep(n) _sleep ((n) * 1000)
  31. #endif
  32. #include <fcntl.h>
  33. #ifndef O_NOATIME
  34. #define O_NOATIME 0
  35. #endif
  36. #ifndef O_NOFOLLOW
  37. #define O_NOFOLLOW 0
  38. #endif
  39. static int const constants[] =
  40. {
  41. O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
  42. O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
  43. };
  44. ]],
  45. [[
  46. int result = !constants;
  47. #if HAVE_SYMLINK
  48. {
  49. static char const sym[] = "conftest.sym";
  50. if (symlink (".", sym) != 0)
  51. result |= 2;
  52. else
  53. {
  54. int fd = open (sym, O_RDONLY | O_NOFOLLOW);
  55. if (fd >= 0)
  56. {
  57. close (fd);
  58. result |= 4;
  59. }
  60. }
  61. unlink (sym);
  62. }
  63. #endif
  64. {
  65. static char const file[] = "confdefs.h";
  66. int fd = open (file, O_RDONLY | O_NOATIME);
  67. if (fd < 0)
  68. result |= 8;
  69. else
  70. {
  71. struct stat st0;
  72. if (fstat (fd, &st0) != 0)
  73. result |= 16;
  74. else
  75. {
  76. char c;
  77. sleep (1);
  78. if (read (fd, &c, 1) != 1)
  79. result |= 24;
  80. else
  81. {
  82. if (close (fd) != 0)
  83. result |= 32;
  84. else
  85. {
  86. struct stat st1;
  87. if (stat (file, &st1) != 0)
  88. result |= 40;
  89. else
  90. if (st0.st_atime != st1.st_atime)
  91. result |= 64;
  92. }
  93. }
  94. }
  95. }
  96. }
  97. return result;]])],
  98. [gl_cv_header_working_fcntl_h=yes],
  99. [case $? in #(
  100. 4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
  101. 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
  102. 68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
  103. *) gl_cv_header_working_fcntl_h='no';;
  104. esac],
  105. [gl_cv_header_working_fcntl_h=cross-compiling])])
  106. case $gl_cv_header_working_fcntl_h in #(
  107. *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
  108. *) ac_val=1;;
  109. esac
  110. AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
  111. [Define to 1 if O_NOATIME works.])
  112. case $gl_cv_header_working_fcntl_h in #(
  113. *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
  114. *) ac_val=1;;
  115. esac
  116. AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
  117. [Define to 1 if O_NOFOLLOW works.])
  118. ])