@@ -54,13 +54,10 @@ use crate::fs::{Mode, OFlags, SeekFrom, Stat};
54
54
#[ cfg( not( any( target_os = "haiku" , target_os = "redox" , target_os = "wasi" ) ) ) ]
55
55
use crate :: fs:: { StatVfs , StatVfsMountFlags } ;
56
56
use crate :: io;
57
- #[ cfg( fix_y2038) ]
57
+ #[ cfg( all ( target_env = "gnu" , fix_y2038) ) ]
58
58
use crate :: timespec:: LibcTimespec ;
59
59
#[ cfg( not( target_os = "wasi" ) ) ]
60
60
use crate :: ugid:: { Gid , Uid } ;
61
- #[ cfg( not( fix_y2038) ) ]
62
- #[ cfg( not( target_os = "espidf" ) ) ]
63
- use crate :: utils:: as_ptr;
64
61
#[ cfg( apple) ]
65
62
use alloc:: vec;
66
63
use core:: mem:: MaybeUninit ;
77
74
core:: ptr:: null,
78
75
} ;
79
76
80
- #[ cfg( fix_y2038) ]
77
+ #[ cfg( all ( target_env = "gnu" , fix_y2038) ) ]
81
78
weak ! ( fn __utimensat64( c:: c_int, * const c:: c_char, * const LibcTimespec , c:: c_int) -> c:: c_int) ;
82
- #[ cfg( fix_y2038) ]
79
+ #[ cfg( all ( target_env = "gnu" , fix_y2038) ) ]
83
80
weak ! ( fn __futimens64( c:: c_int, * const LibcTimespec ) -> c:: c_int) ;
84
81
85
82
/// Use a direct syscall (via libc) for `open`.
@@ -706,31 +703,36 @@ pub(crate) fn utimensat(
706
703
times : & Timestamps ,
707
704
flags : AtFlags ,
708
705
) -> io:: Result < ( ) > {
709
- // 32-bit gnu version: libc has `utimensat` but it is not y2038 safe by
710
- // default.
706
+ // Old 32-bit version: libc has `utimensat` but it is not y2038 safe by
707
+ // default. But there may be a `__utimensat16` we can use.
711
708
#[ cfg( fix_y2038) ]
712
- unsafe {
709
+ {
710
+ #[ cfg( target_env = "gnu" ) ]
713
711
if let Some ( libc_utimensat) = __utimensat64. get ( ) {
714
712
let libc_times: [ LibcTimespec ; 2 ] = [
715
713
times. last_access . clone ( ) . into ( ) ,
716
714
times. last_modification . clone ( ) . into ( ) ,
717
715
] ;
718
716
719
- ret ( libc_utimensat (
720
- borrowed_fd ( dirfd ) ,
721
- c_str ( path ) ,
722
- libc_times . as_ptr ( ) ,
723
- bitflags_bits ! ( flags ) ,
724
- ) )
725
- } else {
726
- utimensat_old ( dirfd , path , times , flags )
717
+ unsafe {
718
+ return ret ( libc_utimensat (
719
+ borrowed_fd ( dirfd ) ,
720
+ c_str ( path ) ,
721
+ libc_times . as_ptr ( ) ,
722
+ bitflags_bits ! ( flags ) ,
723
+ ) ) ;
724
+ }
727
725
}
726
+
727
+ utimensat_old ( dirfd, path, times, flags)
728
728
}
729
729
730
730
// Main version: libc is y2038 safe and has `utimensat`. Or, the platform
731
731
// is not y2038 safe and there's nothing practical we can do.
732
732
#[ cfg( not( any( apple, fix_y2038) ) ) ]
733
733
unsafe {
734
+ use crate :: utils:: as_ptr;
735
+
734
736
// Assert that `Timestamps` has the expected layout.
735
737
let _ = core:: mem:: transmute :: < Timestamps , [ c:: timespec ; 2 ] > ( times. clone ( ) ) ;
736
738
@@ -742,9 +744,11 @@ pub(crate) fn utimensat(
742
744
) )
743
745
}
744
746
745
- // `utimensat` was introduced in macOS 10.13.
747
+ // Apple version: `utimensat` was introduced in macOS 10.13.
746
748
#[ cfg( apple) ]
747
749
unsafe {
750
+ use crate :: utils:: as_ptr;
751
+
748
752
// ABI details
749
753
weak ! {
750
754
fn utimensat(
@@ -859,7 +863,7 @@ pub(crate) fn utimensat(
859
863
}
860
864
861
865
#[ cfg( fix_y2038) ]
862
- unsafe fn utimensat_old (
866
+ fn utimensat_old (
863
867
dirfd : BorrowedFd < ' _ > ,
864
868
path : & CStr ,
865
869
times : & Timestamps ,
@@ -883,12 +887,14 @@ unsafe fn utimensat_old(
883
887
tv_nsec : times. last_modification . tv_nsec ,
884
888
} ,
885
889
] ;
886
- ret ( c:: utimensat (
887
- borrowed_fd ( dirfd) ,
888
- c_str ( path) ,
889
- old_times. as_ptr ( ) ,
890
- bitflags_bits ! ( flags) ,
891
- ) )
890
+ unsafe {
891
+ ret ( c:: utimensat (
892
+ borrowed_fd ( dirfd) ,
893
+ c_str ( path) ,
894
+ old_times. as_ptr ( ) ,
895
+ bitflags_bits ! ( flags) ,
896
+ ) )
897
+ }
892
898
}
893
899
894
900
#[ cfg( not( target_os = "wasi" ) ) ]
@@ -1349,34 +1355,42 @@ fn libc_statvfs_to_statvfs(from: c::statvfs) -> StatVfs {
1349
1355
1350
1356
#[ cfg( not( target_os = "espidf" ) ) ]
1351
1357
pub ( crate ) fn futimens ( fd : BorrowedFd < ' _ > , times : & Timestamps ) -> io:: Result < ( ) > {
1352
- // 32-bit gnu version: libc has `futimens` but it is not y2038 safe by default.
1358
+ // Old 32-bit version: libc has `futimens` but it is not y2038 safe by
1359
+ // default. But there may be a `__futimens64` we can use.
1353
1360
#[ cfg( fix_y2038) ]
1354
- unsafe {
1361
+ {
1362
+ #[ cfg( target_env = "gnu" ) ]
1355
1363
if let Some ( libc_futimens) = __futimens64. get ( ) {
1356
1364
let libc_times: [ LibcTimespec ; 2 ] = [
1357
1365
times. last_access . clone ( ) . into ( ) ,
1358
1366
times. last_modification . clone ( ) . into ( ) ,
1359
1367
] ;
1360
1368
1361
- ret ( libc_futimens ( borrowed_fd ( fd ) , libc_times . as_ptr ( ) ) )
1362
- } else {
1363
- futimens_old ( fd , times )
1369
+ unsafe {
1370
+ return ret ( libc_futimens ( borrowed_fd ( fd ) , libc_times . as_ptr ( ) ) ) ;
1371
+ }
1364
1372
}
1373
+
1374
+ futimens_old ( fd, times)
1365
1375
}
1366
1376
1367
1377
// Main version: libc is y2038 safe and has `futimens`. Or, the platform
1368
1378
// is not y2038 safe and there's nothing practical we can do.
1369
1379
#[ cfg( not( any( apple, fix_y2038) ) ) ]
1370
1380
unsafe {
1381
+ use crate :: utils:: as_ptr;
1382
+
1371
1383
// Assert that `Timestamps` has the expected layout.
1372
1384
let _ = core:: mem:: transmute :: < Timestamps , [ c:: timespec ; 2 ] > ( times. clone ( ) ) ;
1373
1385
1374
1386
ret ( c:: futimens ( borrowed_fd ( fd) , as_ptr ( times) . cast ( ) ) )
1375
1387
}
1376
1388
1377
- // `futimens` was introduced in macOS 10.13.
1389
+ // Apple version: `futimens` was introduced in macOS 10.13.
1378
1390
#[ cfg( apple) ]
1379
1391
unsafe {
1392
+ use crate :: utils:: as_ptr;
1393
+
1380
1394
// ABI details.
1381
1395
weak ! {
1382
1396
fn futimens( c:: c_int, * const c:: timespec) -> c:: c_int
@@ -1413,7 +1427,7 @@ pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()>
1413
1427
}
1414
1428
1415
1429
#[ cfg( fix_y2038) ]
1416
- unsafe fn futimens_old ( fd : BorrowedFd < ' _ > , times : & Timestamps ) -> io:: Result < ( ) > {
1430
+ fn futimens_old ( fd : BorrowedFd < ' _ > , times : & Timestamps ) -> io:: Result < ( ) > {
1417
1431
let old_times = [
1418
1432
c:: timespec {
1419
1433
tv_sec : times
@@ -1433,7 +1447,7 @@ unsafe fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()>
1433
1447
} ,
1434
1448
] ;
1435
1449
1436
- ret ( c:: futimens ( borrowed_fd ( fd) , old_times. as_ptr ( ) ) )
1450
+ unsafe { ret ( c:: futimens ( borrowed_fd ( fd) , old_times. as_ptr ( ) ) ) }
1437
1451
}
1438
1452
1439
1453
#[ cfg( not( any(
0 commit comments