fcntl-o.m4 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # fcntl-o.m4 serial 2
  2. dnl Copyright (C) 2006, 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. 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_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h],
  19. [AC_RUN_IFELSE(
  20. [AC_LANG_PROGRAM(
  21. [[#include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <unistd.h>
  24. #include <fcntl.h>
  25. #ifndef O_NOATIME
  26. #define O_NOATIME 0
  27. #endif
  28. #ifndef O_NOFOLLOW
  29. #define O_NOFOLLOW 0
  30. #endif
  31. static int const constants[] =
  32. {
  33. O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND,
  34. O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY
  35. };
  36. ]],
  37. [[
  38. int status = !constants;
  39. {
  40. static char const sym[] = "conftest.sym";
  41. if (symlink (".", sym) != 0
  42. || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0)
  43. status |= 32;
  44. unlink (sym);
  45. }
  46. {
  47. static char const file[] = "confdefs.h";
  48. int fd = open (file, O_RDONLY | O_NOATIME);
  49. char c;
  50. struct stat st0, st1;
  51. if (fd < 0
  52. || fstat (fd, &st0) != 0
  53. || sleep (1) != 0
  54. || read (fd, &c, 1) != 1
  55. || close (fd) != 0
  56. || stat (file, &st1) != 0
  57. || st0.st_atime != st1.st_atime)
  58. status |= 64;
  59. }
  60. return status;]])],
  61. [gl_cv_header_working_fcntl_h=yes],
  62. [case $? in #(
  63. 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #(
  64. 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #(
  65. 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #(
  66. *) gl_cv_header_working_fcntl_h='no';;
  67. esac],
  68. [gl_cv_header_working_fcntl_h=cross-compiling])])
  69. case $gl_cv_header_working_fcntl_h in #(
  70. *O_NOATIME* | no | cross-compiling) ac_val=0;; #(
  71. *) ac_val=1;;
  72. esac
  73. AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val],
  74. [Define to 1 if O_NOATIME works.])
  75. case $gl_cv_header_working_fcntl_h in #(
  76. *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #(
  77. *) ac_val=1;;
  78. esac
  79. AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val],
  80. [Define to 1 if O_NOFOLLOW works.])
  81. ])