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"