Linux C determines if a file exists "go"

Source: Internet
Author: User
Tags readable

Transferred from: http://blog.csdn.net/kingjo002/article/details/8442146

The function description of Access function: Check whether the calling process can perform some action on the specified file. Usage: #include<unistd.h>#include<fcntl.h>intAccessConst Char*pathname,intmode);   Parameter: Pathname: The path name of the file that needs to be tested. Mode: The operating modes that need to be tested, the possible values are one or more r_ok (readable?), W_ok (writable), X_OK (executable), or F_OK (file exists?).) assembly. Returns a description: returns 0 when successful execution. Failed to return-1, errno is set to one of the following values EINVAL: Invalid mode value eacces: The directory contained in the file or pathname is not accessible eloop: There are too many symbolic connections in the process of interpreting the pathname Enametoolong: path name too long ENOENT: directory in Path name Non-existent or invalid symbolic connection Enotdir: The component in the pathname as a directory is not a directory erofs: File system Read-only Efault: path name points to accessible space EIO: Input output error ENOMEM: Unable to get enough kernel memory Etxtbsy: Error writing program write #include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<fcntl.h>intMain () {if(Access ("test.c", F_OK))!=-1) {printf ("file test.c exists. \ n"); }       Else{printf ("test.c does not exist!\n"); }         if(Access ("test.c", R_OK)!=-1) {printf ("test.c has readable permissions \ n"); }       Else{printf ("test.c not readable. \ n"); }         if(Access ("test.c", W_OK)!=-1) {printf ("test.c have writable permissions \ n"); }       Else{printf ("test.c not writable. \ n"); }       if(Access ("test.c", X_OK)!=-1) {printf ("test.c has executable permissions \ n"); }       Else{printf ("test.c not enforceable. \ n"); }         return 0; } #include<stdio.h>#include<time.h>intMain () {time_t now=Time (NULL); Charbuf[ -]; Strftime (BUF, -,"%y%m%d", LocalTime (&Now )); printf ("%s\n", BUF); Strftime (BUF, -,"%y-%m-%d%h:%m:%s", LocalTime (&Now )); printf ("%s\n", BUF); Strftime (BUF, -,"%y%m%d%h:%m:%s", LocalTime (&Now )); printf ("%s\n", BUF); Strftime (BUF, -,"%y%m%d", LocalTime (&Now )); printf ("%s\n", BUF); Strftime (BUF, -,"%h:%m:%s", LocalTime (&Now )); printf ("%s\n", BUF); return 0; }  

Linux C determines if a file exists "go"

Related Article

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.