1 /* access.c 2 This example shows how to test the existence and the R/W/X permissions 3 of a file. 4 */ 5 #include 6 #include 7 #include 8 main(int argc, char *argv[]) 9 { 10 11 if (access(argv[1], F_OK) < 0) { 12 printf("%s does not exist\n", argv[1]); 13 exit(1); 14 } 15 if (!access(argv[1], R_OK)) 16 printf("%s has R permission\n", argv[1]); 17 if (!access(argv[1], W_OK)) 18 printf("%s has W permission\n", argv[1]); 19 if (!access(argv[1], X_OK)) 20 printf("%s has X permission\n", argv[1]); 21 exit(0); 22 }