1 # include <unistd. h>
2 # include <sys/stat. h>
3 # include <stdio. h>
4
5 bool IsFileRead (const char * file_name)
6 {
7 int ret = access (file_name, R_ OK );
8 /*
9 W_ OK: can write X_ OK? can execute F_ OK?
10 */
11 if (ret = 0)
12 return true;
13 return false;
14}
15 bool IsRegFile (const char * file_name)
16 {
17 struct stat s;
18 if (lstat (file_name, & s)> = 0 & S_ISREG (s. st_mode )){
19 /*
20 S_ISDIR S_ISCHR character device S_ISBLK S_ISFIFO S_ISLNK S_ISSOCK
21 */
22 return true;
23}
24 return false;
25
26/* if (lstat (file_name, & s) <0) {// if the file does not exist, a negative number is returned.
27 printf ("error \ n ");
28 return false;
29}
30 if (S_ISREG (s. st_mode )){
31 return true;
32}
33 return false ;*/
34}
35
36 int main (int argc, char ** argv)
37 {
38 if (IsRegFile (argv [1]) {
39 printf ("exist file: % s \ n", argv [1]);
40} else {
41 printf ("not exist file: % s \ n", argv [1]);
42}
43
44 return 0;
45}