#include <unistd.h>
|
int
access (const char *path, int mode); |
For additional information, see the File Access Permission section of intro . X_OK, the file may not actually have execute permission bits set. Likewise for R_OK and W_OK.
Note that as execute-bit for file is not supported hence access system call for X_OK is undefined.
/** * Detailed description: This sample code checks read-ok accessibility of file Example.c * * Precondtions: Example.txt file should be present in working directory. **/ #include <unistd.h> int main() { if(access("Example.c" ,R_OK) < 0) { printf("Read operation on the file is not permitted \n") ; return -1 ; } printf("Read operation permitted on Example.c file \n") ; return 0 ; }
Output
Read operation permitted on Example.c file
[ENOTDIR] | |
A component of the path prefix is not a directory. | |
[ENAMETOOLONG] | |
A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters (Not supported). | |
[ENOENT] | |
The named file does not exist. | |
[ELOOP] | |
Too many symbolic links were encountered in translating the pathname (Not supported). | |
[EROFS] | |
Write access is requested for a file on a read-only file system (Not supported). | |
[ETXTBSY] | |
Write access is requested for a pure procedure (shared text) file presently being executed(Not supported). | |
[EACCES] | |
Permission bits of the file mode do not permit the requested access, or search permission is denied on a component of the path prefix. | |
[EFAULT] | |
The path argument points outside the process’s allocated address space (Not supported) | |
[EIO] | |
© 2005-2007 Nokia |