@@ -230,16 +230,7 @@ impl FileDesc {
230230 Ok ( ret as usize )
231231 }
232232
233- // We support old MacOS and iOS versions that do not have `preadv`. There is
234- // no `syscall` possible in these platform.
235- #[ cfg( any(
236- all( target_os = "android" , target_pointer_width = "32" ) ,
237- target_os = "ios" , // ios 14.0
238- target_os = "tvos" , // tvos 14.0
239- target_os = "macos" , // macos 11.0
240- target_os = "watchos" , // watchos 7.0
241- target_os = "visionos" , // visionos 1.0
242- ) ) ]
233+ #[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
243234 pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
244235 super :: weak:: weak!( fn preadv64( libc:: c_int, * const libc:: iovec, libc:: c_int, off64_t) -> isize ) ;
245236
@@ -259,6 +250,33 @@ impl FileDesc {
259250 }
260251 }
261252
253+ // We support old MacOS, iOS, watchOS, tvOS and visionOS versions that do not have `preadv`.
254+ // There is no `syscall` possible in these platform for following apple versions:
255+ // ios 14.0
256+ // tvos 14.0
257+ // macos 11.0
258+ // watchos 7.0
259+ // visionos 1.0
260+ #[ cfg( target_vendor = "apple" ) ]
261+ pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
262+ super :: weak:: weak!( fn preadv( libc:: c_int, * const libc:: iovec, libc:: c_int, off64_t) -> isize ) ;
263+
264+ match preadv. get ( ) {
265+ Some ( preadv) => {
266+ let ret = cvt ( unsafe {
267+ preadv (
268+ self . as_raw_fd ( ) ,
269+ bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
270+ cmp:: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
271+ offset as _ ,
272+ )
273+ } ) ?;
274+ Ok ( ret as usize )
275+ }
276+ None => io:: default_read_vectored ( |b| self . read_at ( b, offset) , bufs) ,
277+ }
278+ }
279+
262280 pub fn write ( & self , buf : & [ u8 ] ) -> io:: Result < usize > {
263281 let ret = cvt ( unsafe {
264282 libc:: write (
@@ -387,16 +405,7 @@ impl FileDesc {
387405 Ok ( ret as usize )
388406 }
389407
390- // We support old MacOS and iOS versions that do not have `pwritev`. There is
391- // no `syscall` possible in these platform.
392- #[ cfg( any(
393- all( target_os = "android" , target_pointer_width = "32" ) ,
394- target_os = "ios" , // ios 14.0
395- target_os = "tvos" , // tvos 14.0
396- target_os = "macos" , // macos 11.0
397- target_os = "watchos" , // watchos 7.0
398- target_os = "visionos" , // visionos 1.0
399- ) ) ]
408+ #[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
400409 pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
401410 super :: weak:: weak!( fn pwritev64( libc:: c_int, * const libc:: iovec, libc:: c_int, off64_t) -> isize ) ;
402411
@@ -416,6 +425,33 @@ impl FileDesc {
416425 }
417426 }
418427
428+ // We support old MacOS, iOS, watchOS, tvOS and visionOS versions that do not have `pwritev`.
429+ // There is no `syscall` possible in these platform for following apple versions:
430+ // ios 14.0
431+ // tvos 14.0
432+ // macos 11.0
433+ // watchos 7.0
434+ // visionos 1.0
435+ #[ cfg( target_vendor = "apple" ) ]
436+ pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
437+ super :: weak:: weak!( fn pwritev( libc:: c_int, * const libc:: iovec, libc:: c_int, off64_t) -> isize ) ;
438+
439+ match pwritev. get ( ) {
440+ Some ( pwritev) => {
441+ let ret = cvt ( unsafe {
442+ pwritev (
443+ self . as_raw_fd ( ) ,
444+ bufs. as_ptr ( ) as * const libc:: iovec ,
445+ cmp:: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
446+ offset as _ ,
447+ )
448+ } ) ?;
449+ Ok ( ret as usize )
450+ }
451+ None => io:: default_write_vectored ( |b| self . write_at ( b, offset) , bufs) ,
452+ }
453+ }
454+
419455 #[ cfg( not( any(
420456 target_env = "newlib" ,
421457 target_os = "solaris" ,
0 commit comments