The Access function of Linux C

Source: Internet
Author: User

The Access function of Linux C

Access (): Determine if you have permission to access files

related functions
Stat, Open,chmod,chown,setuid,setgid
Table header File
#include <unistd.h>
defining functions
int Access (const char * pathname, int mode);
function Description
Access () checks whether a file that already exists can be read/written.The parameter mode has several case combinations, R_OK,W_OK,X_OK and F_OK. R_OK,W_OK and X_OK are used to check whether a file has read, write, and execute permissions. The F_OK is used to determine whether the file exists. Because Access ()Verification of authority only, ignoring file patterns or file content, so if a directory is represented as "writable", it means that operations such as creating new files in the directory can be created, rather than implying that the directory can be treated as a file. For example, you will find that DOS files have "executable" permissions, but will fail when executed with EXECVE ().
return value
If all the permissions you want to check are checked, a value of 0 is returned, which indicates success and returns 1if one of the permissions is disabled.
error code
The file specified by the eaccess parameter pathname does not meet the permissions required for the test.
Erofs files to test write permissions exist in the read-only file system.
The Efault parameter pathname pointer is out of the accessible memory space.
The EINVAL parameter mode is incorrect.
Enametoolong parameter pathname too long.
The Enotdir parameter pathname is a directory.
Enomem Core memory is low
The Eloop parameter pathname has too many symbolic connection problems.
EIO I/O access error.
Additional Instructions
Use Access () for user authentication to be particularly cautious, such as an empty file after access () to open () may cause problems with the system security.

Example

#include <unistd.h>
int main ()
{
if (Access ("/etc/passwd", R_OK) = =0)
printf ("/etc/passwd can be read\n");
}
Perform
/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.