fchmodat_AT_SYMLINK_NOFOLLOW_6659.cpp 1.1 KB

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