access.c 474 B

123456789101112131415
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. int main(void) {
  5. if (access("example_dir/1-never-gonna-give-you-up", R_OK | W_OK)) {
  6. perror("access");
  7. return EXIT_FAILURE;
  8. }
  9. if (!access("example_dir/1-never-gonna-give-you-up", X_OK)) {
  10. puts("Accessing a file with X_OK worked even though it... probably... shouldn't?");
  11. puts("Please run `chmod 644 example_dir/*` and try again.");
  12. return EXIT_FAILURE;
  13. }
  14. }