1# fcntl-o.m4 serial 3 2dnl Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl Written by Paul Eggert. 8 9# Test whether the flags O_NOATIME and O_NOFOLLOW actually work. 10# Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise. 11# Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise. 12AC_DEFUN([gl_FCNTL_O_FLAGS], 13[ 14 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW. 15 dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes 16 dnl AC_GNU_SOURCE. 17 m4_ifdef([AC_USE_SYSTEM_EXTENSIONS], 18 [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], 19 [AC_REQUIRE([AC_GNU_SOURCE])]) 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 #include <unistd.h> 26 #include <fcntl.h> 27 #ifndef O_NOATIME 28 #define O_NOATIME 0 29 #endif 30 #ifndef O_NOFOLLOW 31 #define O_NOFOLLOW 0 32 #endif 33 static int const constants[] = 34 { 35 O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, 36 O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY 37 }; 38 ]], 39 [[ 40 int result = !constants; 41 { 42 static char const sym[] = "conftest.sym"; 43 if (symlink (".", sym) != 0) 44 result |= 2; 45 else 46 { 47 int fd = open (sym, O_RDONLY | O_NOFOLLOW); 48 if (fd >= 0) 49 { 50 close (fd); 51 result |= 4; 52 } 53 } 54 unlink (sym); 55 } 56 { 57 static char const file[] = "confdefs.h"; 58 int fd = open (file, O_RDONLY | O_NOATIME); 59 if (fd < 0) 60 result |= 8; 61 else 62 { 63 struct stat st0; 64 if (fstat (fd, &st0) != 0) 65 result |= 16; 66 else 67 { 68 char c; 69 sleep (1); 70 if (read (fd, &c, 1) != 1) 71 result |= 24; 72 else 73 { 74 if (close (fd) != 0) 75 result |= 32; 76 else 77 { 78 struct stat st1; 79 if (stat (file, &st1) != 0) 80 result |= 40; 81 else 82 if (st0.st_atime != st1.st_atime) 83 result |= 64; 84 } 85 } 86 } 87 } 88 } 89 return result;]])], 90 [gl_cv_header_working_fcntl_h=yes], 91 [case $? in #( 92 4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( 93 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( 94 68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( 95 *) gl_cv_header_working_fcntl_h='no';; 96 esac], 97 [gl_cv_header_working_fcntl_h=cross-compiling])]) 98 99 case $gl_cv_header_working_fcntl_h in #( 100 *O_NOATIME* | no | cross-compiling) ac_val=0;; #( 101 *) ac_val=1;; 102 esac 103 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val], 104 [Define to 1 if O_NOATIME works.]) 105 106 case $gl_cv_header_working_fcntl_h in #( 107 *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #( 108 *) ac_val=1;; 109 esac 110 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val], 111 [Define to 1 if O_NOFOLLOW works.]) 112]) 113