@@ -7,6 +7,8 @@ use libc::{self, mode_t};
7
7
use std:: mem;
8
8
use std:: os:: unix:: io:: RawFd ;
9
9
10
+ pub use self :: linux:: * ;
11
+
10
12
mod ffi {
11
13
use libc:: { c_char, c_int, mode_t, dev_t} ;
12
14
pub use libc:: { stat, fstat, lstat} ;
@@ -53,6 +55,7 @@ bitflags! {
53
55
}
54
56
}
55
57
58
+
56
59
pub fn mknod < P : ?Sized + NixPath > ( path : & P , kind : SFlag , perm : Mode , dev : dev_t ) -> Result < ( ) > {
57
60
let res = try!( path. with_nix_path ( |cstr| {
58
61
unsafe {
@@ -171,3 +174,63 @@ pub fn fchmodat<P: ?Sized + NixPath>(dirfd: RawFd, pathname: &P, mode: Mode, fla
171
174
172
175
Errno :: result ( res) . map ( drop)
173
176
}
177
+
178
+ #[ cfg( target_os = "linux" ) ]
179
+ mod linux {
180
+ use { Errno , Result , NixPath } ;
181
+ use std:: os:: unix:: io:: RawFd ;
182
+ use libc;
183
+ use fcntl:: AtFlags ;
184
+ use sys:: time:: TimeSpec ;
185
+
186
+ pub enum UtimeSpec {
187
+ Now ,
188
+ Omit ,
189
+ Time ( TimeSpec )
190
+ }
191
+
192
+ fn to_timespec ( time : & UtimeSpec ) -> libc:: timespec {
193
+ match time {
194
+ & UtimeSpec :: Now => libc:: timespec {
195
+ tv_sec : 0 ,
196
+ tv_nsec : libc:: UTIME_NOW ,
197
+ } ,
198
+ & UtimeSpec :: Omit => libc:: timespec {
199
+ tv_sec : 0 ,
200
+ tv_nsec : libc:: UTIME_OMIT ,
201
+ } ,
202
+ & UtimeSpec :: Time ( spec) => * spec. as_ref ( )
203
+ }
204
+ }
205
+
206
+ pub fn utimensat < P : ?Sized + NixPath > ( dirfd : RawFd ,
207
+ pathname : & P ,
208
+ atime : & UtimeSpec ,
209
+ mtime : & UtimeSpec ,
210
+ flags : AtFlags ) -> Result < ( ) > {
211
+ let time = [ to_timespec ( atime) , to_timespec ( mtime) ] ;
212
+ let res = try!( pathname. with_nix_path ( |cstr| {
213
+ unsafe {
214
+ libc:: utimensat ( dirfd,
215
+ cstr. as_ptr ( ) ,
216
+ time. as_ptr ( ) as * const libc:: timespec ,
217
+ flags. bits ( ) )
218
+ }
219
+ } ) ) ;
220
+
221
+ Errno :: result ( res) . map ( drop)
222
+ }
223
+
224
+ pub fn futimens ( fd : RawFd ,
225
+ atime : & UtimeSpec ,
226
+ mtime : & UtimeSpec ) -> Result < ( ) > {
227
+ let time = [ to_timespec ( atime) , to_timespec ( mtime) ] ;
228
+ let res = unsafe {
229
+ libc:: futimens ( fd, time. as_ptr ( ) as * const libc:: timespec )
230
+ } ;
231
+
232
+ Errno :: result ( res) . map ( drop)
233
+ }
234
+ }
235
+ #[ cfg( not( target_os = "linux" ) ) ]
236
+ mod linux { }
0 commit comments