@@ -68,6 +68,270 @@ pub pure fn Path(s: &str) -> Path {
68
68
PosixPath ( s)
69
69
}
70
70
71
+ #[ cfg( target_os = "linux" ) ]
72
+ mod stat {
73
+ #[ cfg( target_arch = "x86" ) ]
74
+ pub mod arch {
75
+ pub fn default_stat ( ) -> libc:: stat {
76
+ libc:: stat {
77
+ st_dev : 0 ,
78
+ __pad1 : 0 ,
79
+ st_ino : 0 ,
80
+ st_mode : 0 ,
81
+ st_nlink : 0 ,
82
+ st_uid : 0 ,
83
+ st_gid : 0 ,
84
+ st_rdev : 0 ,
85
+ __pad2 : 0 ,
86
+ st_size : 0 ,
87
+ st_blksize : 0 ,
88
+ st_blocks : 0 ,
89
+ st_atime : 0 ,
90
+ st_atime_nsec : 0 ,
91
+ st_mtime : 0 ,
92
+ st_mtime_nsec : 0 ,
93
+ st_ctime : 0 ,
94
+ st_ctime_nsec : 0 ,
95
+ __unused4 : 0 ,
96
+ __unused5 : 0 ,
97
+ }
98
+ }
99
+ }
100
+
101
+ #[ cfg( target_arch = "x86_64" ) ]
102
+ pub mod arch {
103
+ pub fn default_stat ( ) -> libc:: stat {
104
+ libc:: stat {
105
+ st_dev : 0 ,
106
+ st_ino : 0 ,
107
+ st_nlink : 0 ,
108
+ st_mode : 0 ,
109
+ st_uid : 0 ,
110
+ st_gid : 0 ,
111
+ __pad0 : 0 ,
112
+ st_rdev : 0 ,
113
+ st_size : 0 ,
114
+ st_blksize : 0 ,
115
+ st_blocks : 0 ,
116
+ st_atime : 0 ,
117
+ st_atime_nsec : 0 ,
118
+ st_mtime : 0 ,
119
+ st_mtime_nsec : 0 ,
120
+ st_ctime : 0 ,
121
+ st_ctime_nsec : 0 ,
122
+ __unused : [ 0 , 0 , 0 ] ,
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ #[ cfg( target_os = "freebsd" ) ]
129
+ mod stat {
130
+ #[ cfg( target_arch = "x86_64" ) ]
131
+ pub mod arch {
132
+ pub fn default_stat ( ) -> libc:: stat {
133
+ libc:: stat {
134
+ st_dev : 0 ,
135
+ st_ino : 0 ,
136
+ st_mode : 0 ,
137
+ st_nlink : 0 ,
138
+ st_uid : 0 ,
139
+ st_gid : 0 ,
140
+ st_rdev : 0 ,
141
+ st_atime : 0 ,
142
+ st_atime_nsec : 0 ,
143
+ st_mtime : 0 ,
144
+ st_mtime_nsec : 0 ,
145
+ st_ctime : 0 ,
146
+ st_ctime_nsec : 0 ,
147
+ st_size : 0 ,
148
+ st_blocks : 0 ,
149
+ st_blksize : 0 ,
150
+ st_flags : 0 ,
151
+ st_gen : 0 ,
152
+ st_lspare : 0 ,
153
+ st_birthtime : 0 ,
154
+ st_birthtime_nsec : 0 ,
155
+ __unused : [ 0 , 0 ] ,
156
+ }
157
+ }
158
+ }
159
+ }
160
+
161
+ #[ cfg( target_os = "macos" ) ]
162
+ mod stat {
163
+ pub mod arch {
164
+ pub fn default_stat ( ) -> libc:: stat {
165
+ libc:: stat {
166
+ st_dev : 0 ,
167
+ st_mode : 0 ,
168
+ st_nlink : 0 ,
169
+ st_ino : 0 ,
170
+ st_uid : 0 ,
171
+ st_gid : 0 ,
172
+ st_rdev : 0 ,
173
+ st_atime : 0 ,
174
+ st_atime_nsec : 0 ,
175
+ st_mtime : 0 ,
176
+ st_mtime_nsec : 0 ,
177
+ st_ctime : 0 ,
178
+ st_ctime_nsec : 0 ,
179
+ st_birthtime : 0 ,
180
+ st_birthtime_nsec : 0 ,
181
+ st_size : 0 ,
182
+ st_blocks : 0 ,
183
+ st_blksize : 0 ,
184
+ st_flags : 0 ,
185
+ st_gen : 0 ,
186
+ st_lspare : 0 ,
187
+ st_qspare : [ 0 , 0 ] ,
188
+ }
189
+ }
190
+ }
191
+ }
192
+
193
+ #[ cfg( target_os = "windows" ) ]
194
+ mod stat {
195
+ pub mod arch {
196
+ pub fn default_stat ( ) -> libc:: stat {
197
+ libc:: stat {
198
+ st_dev : 0 ,
199
+ st_ino : 0 ,
200
+ st_mode : 0 ,
201
+ st_nlink : 0 ,
202
+ st_uid : 0 ,
203
+ st_gid : 0 ,
204
+ st_rdev : 0 ,
205
+ st_size : 0 ,
206
+ st_atime : 0 ,
207
+ st_mtime : 0 ,
208
+ st_ctime : 0 ,
209
+ }
210
+ }
211
+ }
212
+ }
213
+
214
+
215
+ impl Path {
216
+ fn stat ( & self ) -> Option < libc:: stat > {
217
+ do str:: as_c_str ( self . to_str ( ) ) |buf| {
218
+ let mut st = stat:: arch:: default_stat ( ) ;
219
+ let r = libc:: stat ( buf, ptr:: mut_addr_of ( & st) ) ;
220
+
221
+ if r == 0 { Some ( move st) } else { None }
222
+ }
223
+ }
224
+
225
+ fn lstat ( & self ) -> Option < libc:: stat > {
226
+ do str:: as_c_str ( self . to_str ( ) ) |buf| {
227
+ let mut st = stat:: arch:: default_stat ( ) ;
228
+ let r = libc:: lstat ( buf, ptr:: mut_addr_of ( & st) ) ;
229
+
230
+ if r == 0 { Some ( move st) } else { None }
231
+ }
232
+ }
233
+
234
+ fn exists ( & self ) -> bool {
235
+ match self . stat ( ) {
236
+ None => false ,
237
+ Some ( _) => true ,
238
+ }
239
+ }
240
+
241
+ fn get_size ( & self ) -> Option < i64 > {
242
+ match self . stat ( ) {
243
+ None => None ,
244
+ Some ( ref st) => Some ( st. st_size as i64 ) ,
245
+ }
246
+ }
247
+
248
+ fn get_mode ( & self ) -> Option < uint > {
249
+ match self . stat ( ) {
250
+ None => None ,
251
+ Some ( ref st) => Some ( st. st_mode as uint ) ,
252
+ }
253
+ }
254
+ }
255
+
256
+ #[ cfg( target_os = "freebsd" ) ]
257
+ #[ cfg( target_os = "linux" ) ]
258
+ #[ cfg( target_os = "macos" ) ]
259
+ impl Path {
260
+ fn get_atime ( & self ) -> Option < ( i64 , int ) > {
261
+ match self . stat ( ) {
262
+ None => None ,
263
+ Some ( ref st) => {
264
+ Some ( ( st. st_atime as i64 ,
265
+ st. st_atime_nsec as int ) )
266
+ }
267
+ }
268
+ }
269
+
270
+ fn get_mtime ( & self ) -> Option < ( i64 , int ) > {
271
+ match self . stat ( ) {
272
+ None => None ,
273
+ Some ( ref st) => {
274
+ Some ( ( st. st_mtime as i64 ,
275
+ st. st_mtime_nsec as int ) )
276
+ }
277
+ }
278
+ }
279
+
280
+ fn get_ctime ( & self ) -> Option < ( i64 , int ) > {
281
+ match self . stat ( ) {
282
+ None => None ,
283
+ Some ( ref st) => {
284
+ Some ( ( st. st_ctime as i64 ,
285
+ st. st_ctime_nsec as int ) )
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ #[ cfg( target_os = "freebsd" ) ]
292
+ #[ cfg( target_os = "macos" ) ]
293
+ impl Path {
294
+ fn get_birthtime ( & self ) -> Option < ( i64 , int ) > {
295
+ match self . stat ( ) {
296
+ None => None ,
297
+ Some ( ref st) => {
298
+ Some ( ( st. st_birthtime as i64 ,
299
+ st. st_birthtime_nsec as int ) )
300
+ }
301
+ }
302
+ }
303
+ }
304
+
305
+ #[ cfg( target_os = "win32" ) ]
306
+ impl Path {
307
+ fn get_atime ( & self ) -> Option < ( i64 , int ) > {
308
+ match self . stat ( ) {
309
+ None => None ,
310
+ Some ( ref st) => {
311
+ Some ( ( st. st_atime as i64 , 0 ) )
312
+ }
313
+ }
314
+ }
315
+
316
+ fn get_mtime ( & self ) -> Option < ( i64 , int ) > {
317
+ match self . stat ( ) {
318
+ None => None ,
319
+ Some ( ref st) => {
320
+ Some ( ( st. st_mtime as i64 , 0 ) )
321
+ }
322
+ }
323
+ }
324
+
325
+ fn get_ctime ( & self ) -> Option < ( i64 , int ) > {
326
+ match self . stat ( ) {
327
+ None => None ,
328
+ Some ( ref st) => {
329
+ Some ( ( st. st_ctime as i64 , 0 ) )
330
+ }
331
+ }
332
+ }
333
+ }
334
+
71
335
impl PosixPath : ToStr {
72
336
pure fn to_str ( ) -> ~str {
73
337
let mut s = ~"";
@@ -539,7 +803,7 @@ mod windows {
539
803
}
540
804
}
541
805
542
- #[ cfg ( tests ) ]
806
+ #[ cfg ( test ) ]
543
807
mod tests {
544
808
#[ test]
545
809
fn test_double_slash_collapsing ( ) {
0 commit comments