fcntl-o.m4 2.9 KB

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