@@ -14,6 +14,12 @@ use crate::sys_common::{AsInner, FromInner};
14
14
15
15
use libc:: { c_int, mode_t} ;
16
16
17
+ #[ cfg( any(
18
+ target_os = "macos" ,
19
+ target_os = "ios" ,
20
+ all( target_os = "linux" , target_env = "gnu" )
21
+ ) ) ]
22
+ use libc:: c_char;
17
23
#[ cfg( any( target_os = "linux" , target_os = "emscripten" , target_os = "android" ) ) ]
18
24
use libc:: dirfd;
19
25
#[ cfg( any( target_os = "linux" , target_os = "emscripten" ) ) ]
@@ -92,7 +98,7 @@ cfg_has_statx! {{
92
98
// Default `stat64` contains no creation time.
93
99
unsafe fn try_statx(
94
100
fd: c_int,
95
- path: * const libc :: c_char,
101
+ path: * const c_char,
96
102
flags: i32 ,
97
103
mask: u32 ,
98
104
) -> Option <io:: Result <FileAttr >> {
@@ -107,7 +113,7 @@ cfg_has_statx! {{
107
113
syscall! {
108
114
fn statx(
109
115
fd: c_int,
110
- pathname: * const libc :: c_char,
116
+ pathname: * const c_char,
111
117
flags: c_int,
112
118
mask: libc:: c_uint,
113
119
statxbuf: * mut libc:: statx
@@ -756,7 +762,7 @@ impl File {
756
762
cfg_has_statx ! {
757
763
if let Some ( ret) = unsafe { try_statx(
758
764
fd,
759
- b"\0 " as * const _ as * const libc :: c_char,
765
+ b"\0 " as * const _ as * const c_char,
760
766
libc:: AT_EMPTY_PATH | libc:: AT_STATX_SYNC_AS_STAT ,
761
767
libc:: STATX_ALL ,
762
768
) } {
@@ -1087,15 +1093,28 @@ pub fn link(original: &Path, link: &Path) -> io::Result<()> {
1087
1093
let link = cstr ( link) ?;
1088
1094
cfg_if:: cfg_if! {
1089
1095
if #[ cfg( any( target_os = "vxworks" , target_os = "redox" , target_os = "android" ) ) ] {
1090
- // VxWorks, Redox, and old versions of Android lack `linkat`, so use
1091
- // `link` instead. POSIX leaves it implementation-defined whether
1092
- // `link` follows symlinks, so rely on the `symlink_hard_link` test
1093
- // in library/std/src/fs/tests.rs to check the behavior.
1096
+ // VxWorks and Redox lack `linkat`, so use `link` instead. POSIX leaves
1097
+ // it implementation-defined whether `link` follows symlinks, so rely on the
1098
+ // `symlink_hard_link` test in library/std/src/fs/tests.rs to check the behavior.
1099
+ // Android has `linkat` on newer versions, but we happen to know `link`
1100
+ // always has the correct behavior, so it's here as well.
1094
1101
cvt( unsafe { libc:: link( original. as_ptr( ) , link. as_ptr( ) ) } ) ?;
1102
+ } else if #[ cfg( target_os = "macos" ) ] {
1103
+ // On MacOS, older versions (<=10.9) lack support for linkat while newer
1104
+ // versions have it. We want to use linkat if it is available, so we use weak!
1105
+ // to check. `linkat` is preferable to `link` ecause it gives us a flag to
1106
+ // specify how symlinks should be handled. We pass 0 as the flags argument,
1107
+ // meaning it shouldn't follow symlinks.
1108
+ weak!( fn linkat( c_int, * const c_char, c_int, * const c_char, c_int) -> c_int) ;
1109
+
1110
+ if let Some ( f) = linkat. get( ) {
1111
+ cvt( unsafe { f( libc:: AT_FDCWD , original. as_ptr( ) , libc:: AT_FDCWD , link. as_ptr( ) , 0 ) } ) ?;
1112
+ } else {
1113
+ cvt( unsafe { libc:: link( original. as_ptr( ) , link. as_ptr( ) ) } ) ?;
1114
+ } ;
1095
1115
} else {
1096
- // Use `linkat` with `AT_FDCWD` instead of `link` as `linkat` gives
1097
- // us a flag to specify how symlinks should be handled. Pass 0 as
1098
- // the flags argument, meaning don't follow symlinks.
1116
+ // Where we can, use `linkat` instead of `link`; see the comment above
1117
+ // this one for details on why.
1099
1118
cvt( unsafe { libc:: linkat( libc:: AT_FDCWD , original. as_ptr( ) , libc:: AT_FDCWD , link. as_ptr( ) , 0 ) } ) ?;
1100
1119
}
1101
1120
}
@@ -1278,7 +1297,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1278
1297
fn fclonefileat(
1279
1298
srcfd: libc:: c_int,
1280
1299
dst_dirfd: libc:: c_int,
1281
- dst: * const libc :: c_char,
1300
+ dst: * const c_char,
1282
1301
flags: libc:: c_int
1283
1302
) -> libc:: c_int
1284
1303
}
0 commit comments