Linux access function application example

Source: Internet
Author: User

In the past two days, I learned how to write a linux shell to understand the command in the original dos. COM is also a shell, which of course requires the access of many library functions in c to determine whether the database has the permission to access documents ).

Linux access function Function Description: checks whether a calling process can perform certain operations on a specified file.

Linux access function usage:
# Include
# Include
Int access (const char * pathname, int mode );

Linux access function parameters:
Pathname: name of the file to be tested.
Mode: operation mode to be tested. The value may be one or more R_ OK (readable ?), W_ OK (writable ?), X_ OK (executable ?) Or F_ OK (the file exists ?) Combination body.

Linux access function return instructions:
0 is returned when execution is successful. -1 is returned for failure, and errno is set to one of the following values
EINVAL: the mode value is invalid.
EACCES: the directory in the file or path name is not accessible.
ELOOP: explains that too many symbolic connections exist in the path name process.
ENAMETOOLONG: the path name is too long.
ENOENT: the directory in the path name does not exist or the symbolic connection is invalid.
ENOTDIR: The component used as a directory in the path name is not a directory.
EROFS: File System read-only
EFAULT: the path name points out of the accessible space.
EIO: Input/Output Error
ENOMEM: insufficient kernel memory
ETXTBSY: write error to program

Linux access function example:
 

 
 
  1. /* test.c */ /* test.c */   
  2. #include  
  3. #include  
  4. #include  
  5. #include   
  6. int main(int argc, char *argv[])   
  7. {   
  8. if (argc   
  9. #include  
  10. #include  
  11. #include  
  12. #include   
  13. int main(int argc, char *argv[])   
  14. {   
  15. if (argc   

This article is from the ChinaUnix blog, If you view the original, click: http://blog.chinaunix.net/u3/93782/showart_1915418.html

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.