@@ -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 {
@@ -179,3 +182,70 @@ pub fn fchmodat<P: ?Sized + NixPath>(dirfd: RawFd, pathname: &P, mode: Mode, fla
179
182
180
183
Errno :: result ( res) . map ( drop)
181
184
}
185
+
186
+ #[ cfg( target_os = "linux" ) ]
187
+ mod linux {
188
+ use { Errno , Result , NixPath } ;
189
+ use std:: os:: unix:: io:: RawFd ;
190
+ use libc;
191
+ use fcntl:: AtFlags ;
192
+ use sys:: time:: TimeSpec ;
193
+
194
+ /// A file timestamp.
195
+ pub enum UtimeSpec {
196
+ /// File timestamp is set to the current time.
197
+ Now ,
198
+ /// The corresponding file timestamp is left unchanged.
199
+ Omit ,
200
+ Time ( TimeSpec )
201
+ }
202
+
203
+ fn to_timespec ( time : & UtimeSpec ) -> libc:: timespec {
204
+ match time {
205
+ & UtimeSpec :: Now => libc:: timespec {
206
+ tv_sec : 0 ,
207
+ tv_nsec : libc:: UTIME_NOW ,
208
+ } ,
209
+ & UtimeSpec :: Omit => libc:: timespec {
210
+ tv_sec : 0 ,
211
+ tv_nsec : libc:: UTIME_OMIT ,
212
+ } ,
213
+ & UtimeSpec :: Time ( spec) => * spec. as_ref ( )
214
+ }
215
+ }
216
+
217
+ /// Change file timestamps with nanosecond precision
218
+ /// (see [utimensat(2)](http://man7.org/linux/man-pages/man2/utimensat.2.html)).
219
+ pub fn utimensat < P : ?Sized + NixPath > ( dirfd : RawFd ,
220
+ pathname : & P ,
221
+ atime : & UtimeSpec ,
222
+ mtime : & UtimeSpec ,
223
+ flags : AtFlags ) -> Result < ( ) > {
224
+ let time = [ to_timespec ( atime) , to_timespec ( mtime) ] ;
225
+ let res = try!( pathname. with_nix_path ( |cstr| {
226
+ unsafe {
227
+ libc:: utimensat ( dirfd,
228
+ cstr. as_ptr ( ) ,
229
+ time. as_ptr ( ) as * const libc:: timespec ,
230
+ flags. bits ( ) )
231
+ }
232
+ } ) ) ;
233
+
234
+ Errno :: result ( res) . map ( drop)
235
+ }
236
+
237
+ /// Change file timestamps with nanosecond precision
238
+ /// (see [futimens(2)](http://man7.org/linux/man-pages/man2/futimens.2.html)).
239
+ pub fn futimens ( fd : RawFd ,
240
+ atime : & UtimeSpec ,
241
+ mtime : & UtimeSpec ) -> Result < ( ) > {
242
+ let time = [ to_timespec ( atime) , to_timespec ( mtime) ] ;
243
+ let res = unsafe {
244
+ libc:: futimens ( fd, time. as_ptr ( ) as * const libc:: timespec )
245
+ } ;
246
+
247
+ Errno :: result ( res) . map ( drop)
248
+ }
249
+ }
250
+ #[ cfg( not( target_os = "linux" ) ) ]
251
+ mod linux { }
0 commit comments