Access () function

Source: Internet
Author: User
Access (): functions related to stat, open, chmod, chown, setuid, and setgid to determine whether a file has the permission to be accessed # includeunistd. h defines the function intaccess (constchar * pathname, intmode). The function indicates that access () checks whether an existing file can be read and written. Parameter mode

Access (): functions related to stat, open, chmod, chown, setuid, and setgid to determine whether a file has the permission to be accessed # includeunistd. h defines the function int access (const char * pathname, int mode). The function indicates that access () checks whether an existing file can be read/written. Parameter mode

Access (): determines whether a user has the permission to access a file.

RelatedFunction
Stat, open, chmod, chown, setuid, setgid
Header file
# Include
DefinitionFunction
Int access (const char * pathname, int mode );
FunctionDescription
Access () checks whether an existing file can be read/written. The mode parameter can be combined in several cases: R_ OK, W_ OK, X_ OK, and F_ OK. R_ OK, W_ OK, and X_ OK are used to check whether the file has read, write, and execution permissions. F_ OK is used to determine whether the file exists. Because access () is only used for permission verification and does not care about the file format or content, if a directory is represented as "writable ", indicates that new files can be created in the directory, rather than being processed as files. For example, you will find that all DOS Files have the "executable" permission, but execve () will fail to be executed.
Return Value
If all the permissions to be checked have passed the check, a value of 0 is returned, indicating that the operation is successful. If a permission is disabled,-1 is returned.
Error Code
The file specified by the EACCESS parameter pathname does not meet the required permissions.
The file to be tested by EROFS is stored in the read-only file system.
The pathname pointer of the EFAULT parameter exceeds the accessible memory space.
The mode Val parameter mode is incorrect.
The pathname parameter of ENAMETOOLONG is too long.
The pathname parameter of ENOTDIR is a directory.
Insufficient ENOMEM core memory
The pathname parameter of ELOOP has too many symbolic connections.
Eio I/O access error.
Additional instructions
Be especially careful when using access () for user authentication. For example, making an open () empty file after access () may cause system security problems.

Example

# Include
Int main ()
{
If (access ("/etc/passwd", R_ OK) = 0)
Printf ("/etc/passwd can be read \ n ");
}
Run
/Etc/passwd can be read

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.