Rev 4874 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | 3 | ||
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | #include |
6 | #include |
7 | #include <_syslist.h> |
- | |
8 | #include |
- | |
9 | #include |
- | |
Line 10... | Line 7... | ||
10 | 7 | #include <_syslist.h> |
|
11 | 8 | ||
Line 12... | Line 9... | ||
12 | /* Some targets provides their own versions of these functions. Those |
9 | /* Some targets provides their own versions of these functions. Those |
Line 23... | Line 20... | ||
23 | int _dummy_fstat_syscalls = 1; |
20 | int _dummy_fstat_syscalls = 1; |
Line 24... | Line 21... | ||
24 | 21 | ||
Line 25... | Line 22... | ||
25 | #else |
22 | #else |
- | 23 | ||
- | 24 | /* We use the errno variable used by the system dependent layer. */ |
|
Line 26... | Line 25... | ||
26 | 25 | #undef errno |
|
27 | /* We use the errno variable used by the system dependent layer. */ |
26 | extern int errno; |
28 | 27 | ||
Line 49... | Line 48... | ||
49 | This is a reentrant version of < |
48 | This is a reentrant version of < |
50 | takes a pointer to the global data block, which holds |
49 | takes a pointer to the global data block, which holds |
51 | < |
50 | < |
52 | */ |
51 | */ |
Line 53... | Line -... | ||
53 | - | ||
54 | #pragma pack(push, 1) |
- | |
55 | typedef struct |
- | |
56 | { |
- | |
57 | char sec; |
- | |
58 | char min; |
- | |
59 | char hour; |
- | |
60 | char rsv; |
- | |
61 | }detime_t; |
- | |
62 | - | ||
63 | typedef struct |
- | |
64 | { |
- | |
65 | char day; |
- | |
66 | char month; |
- | |
67 | short year; |
- | |
68 | }dedate_t; |
- | |
69 | - | ||
70 | typedef struct |
- | |
71 | { |
- | |
72 | unsigned attr; |
- | |
73 | unsigned flags; |
- | |
74 | union |
- | |
75 | { |
- | |
76 | detime_t ctime; |
- | |
77 | unsigned cr_time; |
- | |
78 | }; |
- | |
79 | union |
- | |
80 | { |
- | |
81 | dedate_t cdate; |
- | |
82 | unsigned cr_date; |
- | |
83 | }; |
- | |
84 | union |
- | |
85 | { |
- | |
86 | detime_t atime; |
- | |
87 | unsigned acc_time; |
- | |
88 | }; |
- | |
89 | union |
- | |
90 | { |
- | |
91 | dedate_t adate; |
- | |
92 | unsigned acc_date; |
- | |
93 | }; |
- | |
94 | union |
- | |
95 | { |
- | |
96 | detime_t mtime; |
- | |
97 | unsigned mod_time; |
- | |
98 | }; |
- | |
99 | union |
- | |
100 | { |
- | |
101 | dedate_t mdate; |
- | |
102 | unsigned mod_date; |
- | |
103 | }; |
- | |
104 | unsigned size; |
- | |
105 | unsigned size_high; |
- | |
106 | } FILEINFO; |
- | |
107 | - | ||
108 | #pragma pack(pop) |
- | |
109 | - | ||
110 | extern unsigned __NFiles; |
- | |
111 | - | ||
112 | #define __handle_check( __h, __r ) \ |
- | |
113 | if( (__h) < 0 || (__h) > __NFiles ) { \ |
- | |
114 | ptr->_errno = EBADF ; \ |
- | |
115 | return( __r ); \ |
- | |
116 | } |
- | |
117 | 52 | ||
118 | int |
53 | int |
119 | _fstat_r (ptr, fd, pstat) |
54 | _fstat_r (ptr, fd, pstat) |
120 | struct _reent *ptr; |
55 | struct _reent *ptr; |
121 | int fd; |
56 | int fd; |
122 | struct stat *pstat; |
57 | struct stat *pstat; |
123 | { |
- | |
124 | FILEINFO info; |
58 | { |
Line 125... | Line -... | ||
125 | int ret; |
- | |
126 | - | ||
127 | __file_handle *fh; |
- | |
128 | - | ||
129 | __handle_check( fd, -1 ); |
- | |
130 | - | ||
131 | if (fd < 3) |
- | |
132 | { |
- | |
133 | pstat->st_mode = S_IFCHR; |
59 | int ret; |
134 | pstat->st_blksize = 0; |
- | |
135 | return 0; |
- | |
136 | } |
- | |
137 | - | ||
138 | fh = (__file_handle*) __getOSHandle( fd ); |
- | |
139 | get_fileinfo(fh->name, &info); |
60 | |
140 | - | ||
141 | memset (pstat, 0, sizeof (* pstat)); |
61 | errno = 0; |
142 | pstat->st_mode = S_IFREG; |
- | |
143 | pstat->st_blksize = 4096; |
62 | if ((ret = _fstat (fd, pstat)) == -1 && errno != 0) |
144 | pstat->st_size = info.size; |
- | |
145 | return 0; |
- | |
146 | } |
- | |
147 | - | ||
148 | int |
- | |
149 | _DEFUN (fstat, (fd, pstat), |
- | |
150 | int fd _AND |
- | |
151 | struct stat *pstat) |
- | |
152 | { |
63 | ptr->_errno = errno; |
Line 153... | Line 64... | ||
153 | return _fstat_r (_REENT, fd, pstat); |
64 | return ret; |