Access functions in C

Source: Internet
Author: User
Intaccess (constchar * filename, intamode); when the amode parameter is 0, it indicates that the existence of the object is checked. If the object exists, 0 is returned. If the object does not exist,-1 is returned. This function can also check other file attributes: 06 check read/write permissions 04 check read permission 02 check write permission 01 check execution permission 00 check file existence and this

Int access (const char * filename, int amode); when the amode parameter is 0, it indicates that the existence of the object is checked. If the object exists, 0 is returned. If the object does not exist,-1 is returned. This function can also check other file attributes: 06 check read/write permissions 04 check read permission 02 check write permission 01 check execution permission 00 check file existence and this

Int access (const char * filename, int amode );
If the amode parameter is 0, the object existence is checked. If the object exists, 0 is returned. If the object does not exist,-1 is returned.
This function can also check other file attributes:
06 check read/write permissions
04 check read permission
02 check write permission
01 check the execution permission
00 check file existence
Even if the file has no read permission, you can determine whether the file exists or not.
If 0 exists,-1 exists.

C Functions
Function Name: access
Skill: determine the object access permission
Usage: int access (const char * filename, int amode );
[Edit this section] access
Synopsis
# Include
Int _ access (const char * path, int mode );
Description
The access function, when used with files, determines whether the specified file exists and can be accessed as specified by the value of mode. when used with directories, _ access determines only whether the specified directory exists; since under Windows all directories have read and write access.
The mode argument can be one:
00 Existence only
02 Write permission
04 Read permission
06 Read and write permission
Returns
Zero if the file has the given mode,-1 if an error occurs.
Portability:
Windows. Under Unix a similar function exists too.
Note that lcc-win32 accepts both _ access (Microsoft convention) and access.
Program example:
  

  1. # Include
  2. # Include
  3. Int file_exists (char * filename );
  4. Int main (void)
  5. {
  6. Printf ("Does NOTEXIST. FIL exist: % s \ n ",
  7. File_exists ("NOTEXISTS. FIL ")? "YES": "NO ");
  8. Return 0;
  9. }
  10. Int file_exists (char * filename)
  11. {
  12. Return (access (filename, 0) = 0 );
  13. }

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.