@@ -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,67 @@ 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
+ pub enum UtimeSpec {
195
+ Now ,
196
+ Omit ,
197
+ Time ( TimeSpec )
198
+ }
199
+
200
+ fn to_timespec ( time : & UtimeSpec ) -> libc:: timespec {
201
+ match time {
202
+ & UtimeSpec :: Now => libc:: timespec {
203
+ tv_sec : 0 ,
204
+ tv_nsec : libc:: UTIME_NOW ,
205
+ } ,
206
+ & UtimeSpec :: Omit => libc:: timespec {
207
+ tv_sec : 0 ,
208
+ tv_nsec : libc:: UTIME_OMIT ,
209
+ } ,
210
+ & UtimeSpec :: Time ( spec) => * spec. as_ref ( )
211
+ }
212
+ }
213
+
214
+ /// Change file timestamps with nanosecond precision
215
+ /// (see [utimensat(2)](http://man7.org/linux/man-pages/man2/utimensat.2.html))
216
+ pub fn utimensat < P : ?Sized + NixPath > ( dirfd : RawFd ,
217
+ pathname : & P ,
218
+ atime : & UtimeSpec ,
219
+ mtime : & UtimeSpec ,
220
+ flags : AtFlags ) -> Result < ( ) > {
221
+ let time = [ to_timespec ( atime) , to_timespec ( mtime) ] ;
222
+ let res = try!( pathname. with_nix_path ( |cstr| {
223
+ unsafe {
224
+ libc:: utimensat ( dirfd,
225
+ cstr. as_ptr ( ) ,
226
+ time. as_ptr ( ) as * const libc:: timespec ,
227
+ flags. bits ( ) )
228
+ }
229
+ } ) ) ;
230
+
231
+ Errno :: result ( res) . map ( drop)
232
+ }
233
+
234
+ /// Change file timestamps with nanosecond precision
235
+ /// (see [futimens(2)](http://man7.org/linux/man-pages/man2/futimens.2.html))
236
+ pub fn futimens ( fd : RawFd ,
237
+ atime : & UtimeSpec ,
238
+ mtime : & UtimeSpec ) -> Result < ( ) > {
239
+ let time = [ to_timespec ( atime) , to_timespec ( mtime) ] ;
240
+ let res = unsafe {
241
+ libc:: futimens ( fd, time. as_ptr ( ) as * const libc:: timespec )
242
+ } ;
243
+
244
+ Errno :: result ( res) . map ( drop)
245
+ }
246
+ }
247
+ #[ cfg( not( target_os = "linux" ) ) ]
248
+ mod linux { }
0 commit comments