@@ -110,12 +110,13 @@ impl FileDesc {
110
110
target_os = "vita" ,
111
111
target_os = "nuttx"
112
112
) ) ) ]
113
- pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
113
+ pub fn read_vectored ( & self , mut bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
114
+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
114
115
let ret = cvt ( unsafe {
115
116
libc:: readv (
116
117
self . as_raw_fd ( ) ,
117
118
bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
118
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
119
+ bufs. len ( ) as libc:: c_int ,
119
120
)
120
121
} ) ?;
121
122
Ok ( ret as usize )
@@ -200,12 +201,17 @@ impl FileDesc {
200
201
target_os = "netbsd" ,
201
202
target_os = "openbsd" , // OpenBSD 2.7
202
203
) ) ]
203
- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
204
+ pub fn read_vectored_at (
205
+ & self ,
206
+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
207
+ offset : u64 ,
208
+ ) -> io:: Result < usize > {
209
+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
204
210
let ret = cvt ( unsafe {
205
211
libc:: preadv (
206
212
self . as_raw_fd ( ) ,
207
213
bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
208
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
214
+ bufs. len ( ) as libc:: c_int ,
209
215
offset as _ ,
210
216
)
211
217
} ) ?;
@@ -237,7 +243,11 @@ impl FileDesc {
237
243
// passing 64-bits parameters to syscalls, so we fallback to the default
238
244
// implementation if `preadv` is not available.
239
245
#[ cfg( all( target_os = "android" , target_pointer_width = "64" ) ) ]
240
- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
246
+ pub fn read_vectored_at (
247
+ & self ,
248
+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
249
+ offset : u64 ,
250
+ ) -> io:: Result < usize > {
241
251
syscall ! (
242
252
fn preadv(
243
253
fd: libc:: c_int,
@@ -247,19 +257,24 @@ impl FileDesc {
247
257
) -> isize ;
248
258
) ;
249
259
260
+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
250
261
let ret = cvt ( unsafe {
251
262
preadv (
252
263
self . as_raw_fd ( ) ,
253
264
bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
254
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
265
+ bufs. len ( ) as libc:: c_int ,
255
266
offset as _ ,
256
267
)
257
268
} ) ?;
258
269
Ok ( ret as usize )
259
270
}
260
271
261
272
#[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
262
- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
273
+ pub fn read_vectored_at (
274
+ & self ,
275
+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
276
+ offset : u64 ,
277
+ ) -> io:: Result < usize > {
263
278
weak ! (
264
279
fn preadv64(
265
280
fd: libc:: c_int,
@@ -271,11 +286,12 @@ impl FileDesc {
271
286
272
287
match preadv64. get ( ) {
273
288
Some ( preadv) => {
289
+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
274
290
let ret = cvt ( unsafe {
275
291
preadv (
276
292
self . as_raw_fd ( ) ,
277
293
bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
278
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
294
+ bufs. len ( ) as libc:: c_int ,
279
295
offset as _ ,
280
296
)
281
297
} ) ?;
@@ -295,7 +311,11 @@ impl FileDesc {
295
311
// These versions may be newer than the minimum supported versions of OS's we support so we must
296
312
// use "weak" linking.
297
313
#[ cfg( target_vendor = "apple" ) ]
298
- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
314
+ pub fn read_vectored_at (
315
+ & self ,
316
+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
317
+ offset : u64 ,
318
+ ) -> io:: Result < usize > {
299
319
weak ! (
300
320
fn preadv(
301
321
fd: libc:: c_int,
@@ -307,11 +327,12 @@ impl FileDesc {
307
327
308
328
match preadv. get ( ) {
309
329
Some ( preadv) => {
330
+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
310
331
let ret = cvt ( unsafe {
311
332
preadv (
312
333
self . as_raw_fd ( ) ,
313
334
bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
314
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
335
+ bufs. len ( ) as libc:: c_int ,
315
336
offset as _ ,
316
337
)
317
338
} ) ?;
@@ -338,12 +359,13 @@ impl FileDesc {
338
359
target_os = "vita" ,
339
360
target_os = "nuttx"
340
361
) ) ) ]
341
- pub fn write_vectored ( & self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
362
+ pub fn write_vectored ( & self , mut bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
363
+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
342
364
let ret = cvt ( unsafe {
343
365
libc:: writev (
344
366
self . as_raw_fd ( ) ,
345
367
bufs. as_ptr ( ) as * const libc:: iovec ,
346
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
368
+ bufs. len ( ) as libc:: c_int ,
347
369
)
348
370
} ) ?;
349
371
Ok ( ret as usize )
@@ -407,12 +429,13 @@ impl FileDesc {
407
429
target_os = "netbsd" ,
408
430
target_os = "openbsd" , // OpenBSD 2.7
409
431
) ) ]
410
- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
432
+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
433
+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
411
434
let ret = cvt ( unsafe {
412
435
libc:: pwritev (
413
436
self . as_raw_fd ( ) ,
414
437
bufs. as_ptr ( ) as * const libc:: iovec ,
415
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
438
+ bufs. len ( ) as libc:: c_int ,
416
439
offset as _ ,
417
440
)
418
441
} ) ?;
@@ -444,7 +467,7 @@ impl FileDesc {
444
467
// passing 64-bits parameters to syscalls, so we fallback to the default
445
468
// implementation if `pwritev` is not available.
446
469
#[ cfg( all( target_os = "android" , target_pointer_width = "64" ) ) ]
447
- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
470
+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
448
471
syscall ! (
449
472
fn pwritev(
450
473
fd: libc:: c_int,
@@ -454,19 +477,20 @@ impl FileDesc {
454
477
) -> isize ;
455
478
) ;
456
479
480
+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
457
481
let ret = cvt ( unsafe {
458
482
pwritev (
459
483
self . as_raw_fd ( ) ,
460
484
bufs. as_ptr ( ) as * const libc:: iovec ,
461
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
485
+ bufs. len ( ) as libc:: c_int ,
462
486
offset as _ ,
463
487
)
464
488
} ) ?;
465
489
Ok ( ret as usize )
466
490
}
467
491
468
492
#[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
469
- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
493
+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
470
494
weak ! (
471
495
fn pwritev64(
472
496
fd: libc:: c_int,
@@ -478,11 +502,12 @@ impl FileDesc {
478
502
479
503
match pwritev64. get ( ) {
480
504
Some ( pwritev) => {
505
+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
481
506
let ret = cvt ( unsafe {
482
507
pwritev (
483
508
self . as_raw_fd ( ) ,
484
509
bufs. as_ptr ( ) as * const libc:: iovec ,
485
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
510
+ bufs. len ( ) as libc:: c_int ,
486
511
offset as _ ,
487
512
)
488
513
} ) ?;
@@ -502,7 +527,7 @@ impl FileDesc {
502
527
// These versions may be newer than the minimum supported versions of OS's we support so we must
503
528
// use "weak" linking.
504
529
#[ cfg( target_vendor = "apple" ) ]
505
- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
530
+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
506
531
weak ! (
507
532
fn pwritev(
508
533
fd: libc:: c_int,
@@ -514,11 +539,12 @@ impl FileDesc {
514
539
515
540
match pwritev. get ( ) {
516
541
Some ( pwritev) => {
542
+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
517
543
let ret = cvt ( unsafe {
518
544
pwritev (
519
545
self . as_raw_fd ( ) ,
520
546
bufs. as_ptr ( ) as * const libc:: iovec ,
521
- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
547
+ bufs. len ( ) as libc:: c_int ,
522
548
offset as _ ,
523
549
)
524
550
} ) ?;
0 commit comments