@@ -45,13 +45,9 @@ const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
45
45
#[ cfg( any(
46
46
target_os = "dragonfly" ,
47
47
target_os = "freebsd" ,
48
- target_os = "ios" ,
49
- target_os = "tvos" ,
50
- target_os = "macos" ,
51
48
target_os = "netbsd" ,
52
49
target_os = "openbsd" ,
53
- target_os = "watchos" ,
54
- target_os = "visionos" ,
50
+ target_vendor = "apple" ,
55
51
) ) ]
56
52
const fn max_iov ( ) -> usize {
57
53
libc:: IOV_MAX as usize
@@ -72,17 +68,13 @@ const fn max_iov() -> usize {
72
68
target_os = "dragonfly" ,
73
69
target_os = "emscripten" ,
74
70
target_os = "freebsd" ,
75
- target_os = "ios" ,
76
- target_os = "tvos" ,
77
71
target_os = "linux" ,
78
- target_os = "macos" ,
79
72
target_os = "netbsd" ,
80
73
target_os = "nto" ,
81
74
target_os = "openbsd" ,
82
75
target_os = "horizon" ,
83
76
target_os = "vita" ,
84
- target_os = "watchos" ,
85
- target_os = "visionos" ,
77
+ target_vendor = "apple" ,
86
78
) ) ) ]
87
79
const fn max_iov ( ) -> usize {
88
80
16 // The minimum value required by POSIX.
@@ -201,13 +193,10 @@ impl FileDesc {
201
193
target_os = "fuchsia" ,
202
194
target_os = "hurd" ,
203
195
target_os = "illumos" ,
204
- target_os = "ios" ,
205
- target_os = "tvos" ,
206
196
target_os = "linux" ,
207
- target_os = "macos" ,
208
197
target_os = "netbsd" ,
209
198
target_os = "openbsd" ,
210
- target_os = "watchos " ,
199
+ target_vendor = "apple " ,
211
200
) ) ) ]
212
201
pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
213
202
io:: default_read_vectored ( |b| self . read_at ( b, offset) , bufs)
@@ -241,15 +230,7 @@ impl FileDesc {
241
230
Ok ( ret as usize )
242
231
}
243
232
244
- // We support old MacOS and iOS versions that do not have `preadv`. There is
245
- // no `syscall` possible in these platform.
246
- #[ cfg( any(
247
- all( target_os = "android" , target_pointer_width = "32" ) ,
248
- target_os = "ios" , // ios 14.0
249
- target_os = "tvos" , // tvos 14.0
250
- target_os = "macos" , // macos 11.0
251
- target_os = "watchos" , // watchos 7.0
252
- ) ) ]
233
+ #[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
253
234
pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
254
235
super :: weak:: weak!( fn preadv64( libc:: c_int, * const libc:: iovec, libc:: c_int, off64_t) -> isize ) ;
255
236
@@ -269,6 +250,35 @@ impl FileDesc {
269
250
}
270
251
}
271
252
253
+ // We support old MacOS, iOS, watchOS, tvOS and visionOS. `preadv` was added in the following
254
+ // Apple OS versions:
255
+ // ios 14.0
256
+ // tvos 14.0
257
+ // macos 11.0
258
+ // watchos 7.0
259
+ //
260
+ // These versions may be newer than the minimum supported versions of OS's we support so we must
261
+ // use "weak" linking.
262
+ #[ cfg( target_vendor = "apple" ) ]
263
+ pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
264
+ super :: weak:: weak!( fn preadv( libc:: c_int, * const libc:: iovec, libc:: c_int, off64_t) -> isize ) ;
265
+
266
+ match preadv. get ( ) {
267
+ Some ( preadv) => {
268
+ let ret = cvt ( unsafe {
269
+ preadv (
270
+ self . as_raw_fd ( ) ,
271
+ bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
272
+ cmp:: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
273
+ offset as _ ,
274
+ )
275
+ } ) ?;
276
+ Ok ( ret as usize )
277
+ }
278
+ None => io:: default_read_vectored ( |b| self . read_at ( b, offset) , bufs) ,
279
+ }
280
+ }
281
+
272
282
pub fn write ( & self , buf : & [ u8 ] ) -> io:: Result < usize > {
273
283
let ret = cvt ( unsafe {
274
284
libc:: write (
@@ -360,13 +370,10 @@ impl FileDesc {
360
370
target_os = "fuchsia" ,
361
371
target_os = "hurd" ,
362
372
target_os = "illumos" ,
363
- target_os = "ios" ,
364
- target_os = "tvos" ,
365
373
target_os = "linux" ,
366
- target_os = "macos" ,
367
374
target_os = "netbsd" ,
368
375
target_os = "openbsd" ,
369
- target_os = "watchos " ,
376
+ target_vendor = "apple " ,
370
377
) ) ) ]
371
378
pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
372
379
io:: default_write_vectored ( |b| self . write_at ( b, offset) , bufs)
@@ -400,15 +407,7 @@ impl FileDesc {
400
407
Ok ( ret as usize )
401
408
}
402
409
403
- // We support old MacOS and iOS versions that do not have `pwritev`. There is
404
- // no `syscall` possible in these platform.
405
- #[ cfg( any(
406
- all( target_os = "android" , target_pointer_width = "32" ) ,
407
- target_os = "ios" , // ios 14.0
408
- target_os = "tvos" , // tvos 14.0
409
- target_os = "macos" , // macos 11.0
410
- target_os = "watchos" , // watchos 7.0
411
- ) ) ]
410
+ #[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
412
411
pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
413
412
super :: weak:: weak!( fn pwritev64( libc:: c_int, * const libc:: iovec, libc:: c_int, off64_t) -> isize ) ;
414
413
@@ -428,6 +427,35 @@ impl FileDesc {
428
427
}
429
428
}
430
429
430
+ // We support old MacOS, iOS, watchOS, tvOS and visionOS. `pwritev` was added in the following
431
+ // Apple OS versions:
432
+ // ios 14.0
433
+ // tvos 14.0
434
+ // macos 11.0
435
+ // watchos 7.0
436
+ //
437
+ // These versions may be newer than the minimum supported versions of OS's we support so we must
438
+ // use "weak" linking.
439
+ #[ cfg( target_vendor = "apple" ) ]
440
+ pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
441
+ super :: weak:: weak!( fn pwritev( libc:: c_int, * const libc:: iovec, libc:: c_int, off64_t) -> isize ) ;
442
+
443
+ match pwritev. get ( ) {
444
+ Some ( pwritev) => {
445
+ let ret = cvt ( unsafe {
446
+ pwritev (
447
+ self . as_raw_fd ( ) ,
448
+ bufs. as_ptr ( ) as * const libc:: iovec ,
449
+ cmp:: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
450
+ offset as _ ,
451
+ )
452
+ } ) ?;
453
+ Ok ( ret as usize )
454
+ }
455
+ None => io:: default_write_vectored ( |b| self . write_at ( b, offset) , bufs) ,
456
+ }
457
+ }
458
+
431
459
#[ cfg( not( any(
432
460
target_env = "newlib" ,
433
461
target_os = "solaris" ,
0 commit comments