1 | /* code to test stat(2) */ |
---|
2 | |
---|
3 | #include <sys/stat.h> |
---|
4 | #include <sys/syscall.h> |
---|
5 | #include <stdio.h> |
---|
6 | |
---|
7 | int main (int argc, char *argv[]) |
---|
8 | { |
---|
9 | struct stat s1; |
---|
10 | struct stat s2; |
---|
11 | if (argc < 2) { |
---|
12 | printf("path arg required\n"); |
---|
13 | return 1; |
---|
14 | } |
---|
15 | |
---|
16 | printf("calling stat syscall directly:\n"); |
---|
17 | if(syscall(SYS_stat, argv[1], &s1) == -1) { |
---|
18 | perror("stat syscall failed"); |
---|
19 | return 1; |
---|
20 | } |
---|
21 | printf("path = %s\n", argv[1]); |
---|
22 | printf("s1.st_mode = %x\n", s1.st_mode); |
---|
23 | printf("S_ISDIR(s1.st_mode) = %d\n", S_ISDIR(s1.st_mode)); |
---|
24 | |
---|
25 | printf("\ncalling stat function:\n"); |
---|
26 | if(stat(argv[1], &s2) == -1) { |
---|
27 | perror("stat failed"); |
---|
28 | return 1; |
---|
29 | } |
---|
30 | printf("path = %s\n", argv[1]); |
---|
31 | printf("s2.st_mode = %x\n", s2.st_mode); |
---|
32 | printf("S_ISDIR(s2.st_mode) = %d\n", S_ISDIR(s2.st_mode)); |
---|
33 | |
---|
34 | return 0; |
---|
35 | } |
---|