gtpc2m0b | C/C++ Language Support User's Guide |
This function determines how the requesting process can access a file. When checking to see if a process has appropriate permissions, the access function looks at the real user ID (UID) and real group ID (GID) of the process, not the effective UID and effective GID.
Format
#include <unistd.h> int access(const char *pathname, int how);
The following symbols are defined in the unistd.h header file for use in the how parameter:
You can take the bitwise inclusive OR of any or all of the last three symbols to test several access modes at once. If you are using F_OK to test for the existence of a file, you cannot use OR with any of the other symbols.
Normal Return
The returned value of access is zero if the specified access is permitted.
Error Return
If unsuccessful, the access function returns -1 and sets sets errno to one of the following:
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Examples
The following example determines how a file is accessed.
#include <unistd.h> #include <stdio.h> main() { char path[]="/"; if (access(path, F_OK) != 0) printf("'%s' does not exist!\n", path); else { if (access(path, R_OK) == 0) printf("You have read access to '%s'\n", path); if (access(path, W_OK) == 0) printf("You have write access to '%s'\n", path); if (access(path, X_OK) == 0) printf("You have search access to '%s'\n", path); } }
Output
You have read access to '/' You have search access to '/'
Related Information
chmod-Change the Mode of a File or Directory.
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.