Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4973 | right-hear | 1 | #include |
2 | #include |
||
3 | #include |
||
4 | #include |
||
5 | #include |
||
6 | #include |
||
7 | #include |
||
8 | #include |
||
9 | #include |
||
10 | #include |
||
11 | #include |
||
12 | #include |
||
13 | #include |
||
14 | #include |
||
15 | #include |
||
16 | #include |
||
17 | |||
18 | #include "xstat.h" |
||
19 | |||
20 | int stat(const char *path, struct stat *statbuf) |
||
21 | { |
||
22 | int nslash=0; |
||
23 | const char* p; |
||
24 | char* q; |
||
25 | struct systree_info2 finf; |
||
26 | struct bdfe_item attr; |
||
27 | |||
28 | memset(statbuf,0,sizeof(*statbuf)); |
||
29 | // "/ |
||
30 | for (p=path;*p;p++) if (*p=='/') ++nslash; |
||
31 | while (p>path && p[-1]=='/') {--nslash;--p;} |
||
32 | if (nslash <= 2) |
||
33 | { |
||
34 | statbuf->st_mode = S_IFDIR; |
||
35 | return 0; |
||
36 | } |
||
37 | finf.command = 5; |
||
38 | finf.file_offset_low = 0; |
||
39 | finf.file_offset_high = 0; |
||
40 | finf.size = 0; |
||
41 | finf.data_pointer = (__u32)&attr; |
||
42 | _fixpath(path,finf.name); |
||
43 | for (q=finf.name+strlen(finf.name)-1;q>=finf.name && *q=='/';q--) ; |
||
44 | q[1]=0; |
||
45 | if (__kolibri__system_tree_access2(&finf)) |
||
46 | { |
||
47 | errno = EFAULT; |
||
48 | return -1; |
||
49 | } |
||
50 | memset(statbuf,0,sizeof(*statbuf)); |
||
51 | statbuf->st_size = attr.filesize_low; |
||
52 | if (attr.attr & 0x10) |
||
53 | statbuf->st_mode = S_IFDIR; |
||
54 | struct tm time; |
||
55 | time.tm_sec = attr.atime.seconds; |
||
56 | time.tm_min = attr.atime.minutes; |
||
57 | time.tm_hour = attr.atime.hours; |
||
58 | time.tm_mday = attr.adate.day; |
||
59 | time.tm_mon = attr.adate.month; |
||
60 | time.tm_year = attr.adate.year - 1900; |
||
61 | time.tm_isdst = -1; |
||
62 | statbuf->st_atime = mktime(&time); |
||
63 | time.tm_sec = attr.ctime.seconds; |
||
64 | time.tm_min = attr.ctime.minutes; |
||
65 | time.tm_hour = attr.ctime.hours; |
||
66 | time.tm_mday = attr.cdate.day; |
||
67 | time.tm_mon = attr.cdate.month; |
||
68 | time.tm_year = attr.cdate.year - 1900; |
||
69 | time.tm_isdst = -1; |
||
70 | statbuf->st_ctime = mktime(&time); |
||
71 | time.tm_sec = attr.mtime.seconds; |
||
72 | time.tm_min = attr.mtime.minutes; |
||
73 | time.tm_hour = attr.mtime.hours; |
||
74 | time.tm_mday = attr.mdate.day; |
||
75 | time.tm_mon = attr.mdate.month; |
||
76 | time.tm_year = attr.mdate.year - 1900; |
||
77 | time.tm_isdst = -1; |
||
78 | statbuf->st_mtime = mktime(&time); |
||
79 | return 0; |
||
80 | }=> |