Created
December 21, 2013 01:27
-
-
Save johnbartholomew/8064239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <errno.h> | |
static void check_access(const char *path) { | |
int ret = access(path, F_OK); | |
if (ret == -1) { | |
int e = errno; | |
printf("access '%s' failed: %s\n", path, strerror(e)); | |
} else { | |
printf("access '%s' ok\n", path); | |
} | |
} | |
int main(void) { | |
check_access(""); /* outputs (for me): access '' failed: No such file or directory */ | |
check_access("/"); /* outputs (for me): access '/' ok */ | |
check_access("/root"); /* outputs (for me): access '/root' ok */ | |
check_access("/root/."); /* outputs (for me): access '/root/.' failed: Permission denied */ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment