1 // Test program to demonstrate that Linux does not support AT_SYMLINK_NOFOLLOW
2
3 // Copyright Duncan Exon Smith 2012
4
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7
8 // Test this by running:
9 //
10 // rm -rf data && mkdir data && g++ -otest-fchmodat fchmodat_AT_SYMLINK_NOFOLLOW_6659.cpp && (cd data && ../test-fchmodat)
11 //
12 // If no assertions go off, then it looks like fchmodat is supported,
13 // but AT_SYMLINK_NOFOLLOW is not supported.
14
15 #include <fstream>
16 #include <cassert>
17 #include <fcntl.h>
18 #include <sys/stat.h>
19 #include <cerrno>
20
21 #ifdef NDEBUG
22 # error This program depends on assert() so makes no sense if NDEBUG is defined
23 #endif
24
main(int argc,char * argv[])25 int main(int argc, char *argv[])
26 {
27 { std::ofstream file("out"); file << "contents"; }
28
29 assert(!::symlink("out", "sym"));
30
31 assert(!::fchmodat(AT_FDCWD, "out", S_IRUSR | S_IWUSR | S_IXUSR, 0));
32 assert(!::fchmodat(AT_FDCWD, "sym", S_IRUSR | S_IWUSR | S_IXUSR, 0));
33
34 assert(::fchmodat(AT_FDCWD, "sym", S_IRUSR | S_IWUSR | S_IXUSR, AT_SYMLINK_NOFOLLOW) == -1);
35 assert(errno == ENOTSUP);
36
37 return 0;
38 }
39