| 1 | #include <unistd.h> |
| 2 | #include <stdio.h> |
| 3 | #include <dirent.h> |
| 4 | #include <errno.h> |
| 5 | |
| 6 | int main(int argc, char *argv[]) { |
| 7 | |
| 8 | char *lex_path; |
| 9 | DIR *path; |
| 10 | struct dirent *dent; |
| 11 | |
| 12 | extern int errno; |
| 13 | |
| 14 | if(argc == 1) |
| 15 | lex_path = "./"; |
| 16 | |
| 17 | else if(argc == 2) |
| 18 | lex_path = argv[1]; |
| 19 | |
| 20 | else { |
| 21 | |
| 22 | printf("inappropriate number of args.\n"); |
| 23 | return 1; |
| 24 | } |
| 25 | |
| 26 | if(!(path = opendir(path))) { |
| 27 | |
| 28 | if(errno == EACCES) |
| 29 | printf("improper permissions to read dir.\n"); |
| 30 | |
| 31 | else if(errno == ENOENT) |
| 32 | printf("given directory does not exist.\n"); |
| 33 | |
| 34 | else if(errno == ENFILE) |
| 35 | printf("we're out of fd's.\n"); |
| 36 | |
| 37 | else if(errno == ENOTDIR) |
| 38 | printf("argument is not a directory.\n"); |
| 39 | |
| 40 | else |
| 41 | printf("an unspecified error occurred.\n"); |
| 42 | |
| 43 | return errno; |
| 44 | } |
| 45 | |
| 46 | if((dent = readdir(path)) != NULL) { |
| 47 | |
| 48 | if( |
| 49 | } |
| 50 | |
| 51 | return 0; |
| 52 | } |