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