Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | ls | 1 | #include <stdio.h> |
2 | #include <sys/stat.h> |
||
3 | |||
4 | // ============================================================================ |
||
5 | // Functions |
||
6 | // ============================================================================ |
||
7 | |||
8 | // functions return 1 if true |
||
9 | |||
10 | int testfile(char *file, unsigned type) |
||
11 | { |
||
12 | int returnvalue; |
||
13 | |||
14 | struct stat buf; |
||
15 | if (lstat (file, &buf) == 0) |
||
16 | { |
||
17 | // its a file, test if a synlink |
||
18 | returnvalue = (( buf.st_mode & S_IFMT) == type); |
||
19 | } |
||
20 | else |
||
21 | { |
||
22 | // its not even a file |
||
23 | returnvalue = 0; |
||
24 | } |
||
25 | return returnvalue; |
||
26 | } |
||
27 | |||
28 | int isregular(char *file) { return testfile(file, S_IFREG); } |
||
29 | int issymlink(char *file) { return testfile(file, S_IFLNK); } |
||
30 | int isdir(char *file) { return testfile(file, S_IFDIR); } |