Ticket #6659: test-fchmodat.cpp

File test-fchmodat.cpp, 727 bytes (added by Duncan Exon Smith <duncanphilipnorman@…>, 10 years ago)

Test program to demonstrate that Linux does not support AT_SYMLINK_NOFOLLOW.

Line 
1
2// Test this by running:
3//
4// rm -rf data && mkdir data && g++ -otest-fchmodat test-fchmodat.cpp && (cd data && ../test-fchmodat)
5//
6// If no assertions go off, then it looks like fchmodat is supported.
7
8#include <fstream>
9#include <cassert>
10#include <fcntl.h>
11#include <sys/stat.h>
12#include <cerrno>
13
14int main(int argc, char *argv[])
15{
16 { std::ofstream file("out"); file << "contents"; }
17
18 assert(!::symlink("out", "sym"));
19
20 assert(!::fchmodat(AT_FDCWD, "out", S_IRUSR | S_IWUSR | S_IXUSR, 0));
21 assert(!::fchmodat(AT_FDCWD, "sym", S_IRUSR | S_IWUSR | S_IXUSR, 0));
22
23 assert(::fchmodat(AT_FDCWD, "sym", S_IRUSR | S_IWUSR | S_IXUSR, AT_SYMLINK_NOFOLLOW) == -1);
24 assert(errno == ENOTSUP);
25
26 return 0;
27}