@@ -193,9 +193,13 @@ feature! {
193
193
194
194
// The conversion is not identical on all operating systems.
195
195
#[ allow( clippy:: useless_conversion) ]
196
- pub fn open<P : ?Sized + NixPath >( path: & P , oflag: OFlag , mode: Mode ) -> Result <RawFd > {
197
- let fd = path. with_nix_path( |cstr| {
198
- unsafe { libc:: open( cstr. as_ptr( ) , oflag. bits( ) , mode. bits( ) as c_uint) }
196
+ pub fn open<P : ?Sized + NixPath >(
197
+ path: & P ,
198
+ oflag: OFlag ,
199
+ mode: Mode ,
200
+ ) -> Result <RawFd > {
201
+ let fd = path. with_nix_path( |cstr| unsafe {
202
+ libc:: open( cstr. as_ptr( ) , oflag. bits( ) , mode. bits( ) as c_uint)
199
203
} ) ?;
200
204
201
205
Errno :: result( fd)
@@ -210,8 +214,8 @@ pub fn openat<P: ?Sized + NixPath>(
210
214
oflag: OFlag ,
211
215
mode: Mode ,
212
216
) -> Result <RawFd > {
213
- let fd = path. with_nix_path( |cstr| {
214
- unsafe { libc:: openat( dirfd, cstr. as_ptr( ) , oflag. bits( ) , mode. bits( ) as c_uint) }
217
+ let fd = path. with_nix_path( |cstr| unsafe {
218
+ libc:: openat( dirfd, cstr. as_ptr( ) , oflag. bits( ) , mode. bits( ) as c_uint)
215
219
} ) ?;
216
220
Errno :: result( fd)
217
221
}
@@ -303,7 +307,10 @@ fn readlink_maybe_at<P: ?Sized + NixPath>(
303
307
} )
304
308
}
305
309
306
- fn inner_readlink<P : ?Sized + NixPath >( dirfd: Option <RawFd >, path: & P ) -> Result <OsString > {
310
+ fn inner_readlink<P : ?Sized + NixPath >(
311
+ dirfd: Option <RawFd >,
312
+ path: & P ,
313
+ ) -> Result <OsString > {
307
314
let mut v = Vec :: with_capacity( libc:: PATH_MAX as usize ) ;
308
315
309
316
{
@@ -387,7 +394,10 @@ pub fn readlink<P: ?Sized + NixPath>(path: &P) -> Result<OsString> {
387
394
}
388
395
389
396
#[ cfg( not( target_os = "redox" ) ) ]
390
- pub fn readlinkat<P : ?Sized + NixPath >( dirfd: RawFd , path: & P ) -> Result <OsString > {
397
+ pub fn readlinkat<P : ?Sized + NixPath >(
398
+ dirfd: RawFd ,
399
+ path: & P ,
400
+ ) -> Result <OsString > {
391
401
inner_readlink( Some ( dirfd) , path)
392
402
}
393
403
@@ -450,9 +460,17 @@ pub enum FcntlArg<'a> {
450
460
F_OFD_SETLKW ( & ' a libc:: flock) ,
451
461
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
452
462
F_OFD_GETLK ( & ' a mut libc:: flock) ,
453
- #[ cfg( any( target_os = "android" , target_os = "linux" , target_os = "freebsd" ) ) ]
463
+ #[ cfg( any(
464
+ target_os = "android" ,
465
+ target_os = "linux" ,
466
+ target_os = "freebsd"
467
+ ) ) ]
454
468
F_ADD_SEALS ( SealFlag ) ,
455
- #[ cfg( any( target_os = "android" , target_os = "linux" , target_os = "freebsd" ) ) ]
469
+ #[ cfg( any(
470
+ target_os = "android" ,
471
+ target_os = "linux" ,
472
+ target_os = "freebsd"
473
+ ) ) ]
456
474
F_GET_SEALS ,
457
475
#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
458
476
F_FULLFSYNC ,
@@ -481,7 +499,9 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
481
499
let res = unsafe {
482
500
match arg {
483
501
F_DUPFD ( rawfd) => libc:: fcntl( fd, libc:: F_DUPFD , rawfd) ,
484
- F_DUPFD_CLOEXEC ( rawfd) => libc:: fcntl( fd, libc:: F_DUPFD_CLOEXEC , rawfd) ,
502
+ F_DUPFD_CLOEXEC ( rawfd) => {
503
+ libc:: fcntl( fd, libc:: F_DUPFD_CLOEXEC , rawfd)
504
+ }
485
505
F_GETFD => libc:: fcntl( fd, libc:: F_GETFD ) ,
486
506
F_SETFD ( flag) => libc:: fcntl( fd, libc:: F_SETFD , flag. bits( ) ) ,
487
507
F_GETFL => libc:: fcntl( fd, libc:: F_GETFL ) ,
@@ -498,9 +518,19 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
498
518
F_OFD_SETLKW ( flock) => libc:: fcntl( fd, libc:: F_OFD_SETLKW , flock) ,
499
519
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
500
520
F_OFD_GETLK ( flock) => libc:: fcntl( fd, libc:: F_OFD_GETLK , flock) ,
501
- #[ cfg( any( target_os = "android" , target_os = "linux" , target_os = "freebsd" ) ) ]
502
- F_ADD_SEALS ( flag) => libc:: fcntl( fd, libc:: F_ADD_SEALS , flag. bits( ) ) ,
503
- #[ cfg( any( target_os = "android" , target_os = "linux" , target_os = "freebsd" ) ) ]
521
+ #[ cfg( any(
522
+ target_os = "android" ,
523
+ target_os = "linux" ,
524
+ target_os = "freebsd"
525
+ ) ) ]
526
+ F_ADD_SEALS ( flag) => {
527
+ libc:: fcntl( fd, libc:: F_ADD_SEALS , flag. bits( ) )
528
+ }
529
+ #[ cfg( any(
530
+ target_os = "android" ,
531
+ target_os = "linux" ,
532
+ target_os = "freebsd"
533
+ ) ) ]
504
534
F_GET_SEALS => libc:: fcntl( fd, libc:: F_GET_SEALS ) ,
505
535
#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
506
536
F_FULLFSYNC => libc:: fcntl( fd, libc:: F_FULLFSYNC ) ,
@@ -535,8 +565,12 @@ pub fn flock(fd: RawFd, arg: FlockArg) -> Result<()> {
535
565
LockShared => libc:: flock( fd, libc:: LOCK_SH ) ,
536
566
LockExclusive => libc:: flock( fd, libc:: LOCK_EX ) ,
537
567
Unlock => libc:: flock( fd, libc:: LOCK_UN ) ,
538
- LockSharedNonblock => libc:: flock( fd, libc:: LOCK_SH | libc:: LOCK_NB ) ,
539
- LockExclusiveNonblock => libc:: flock( fd, libc:: LOCK_EX | libc:: LOCK_NB ) ,
568
+ LockSharedNonblock => {
569
+ libc:: flock( fd, libc:: LOCK_SH | libc:: LOCK_NB )
570
+ }
571
+ LockExclusiveNonblock => {
572
+ libc:: flock( fd, libc:: LOCK_EX | libc:: LOCK_NB )
573
+ }
540
574
UnlockNonblock => libc:: flock( fd, libc:: LOCK_UN | libc:: LOCK_NB ) ,
541
575
}
542
576
} ;
@@ -632,12 +666,19 @@ pub fn splice(
632
666
. map( |offset| offset as * mut libc:: loff_t)
633
667
. unwrap_or( ptr:: null_mut( ) ) ;
634
668
635
- let ret = unsafe { libc:: splice( fd_in, off_in, fd_out, off_out, len, flags. bits( ) ) } ;
669
+ let ret = unsafe {
670
+ libc:: splice( fd_in, off_in, fd_out, off_out, len, flags. bits( ) )
671
+ } ;
636
672
Errno :: result( ret) . map( |r| r as usize )
637
673
}
638
674
639
675
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
640
- pub fn tee( fd_in: RawFd , fd_out: RawFd , len: usize , flags: SpliceFFlags ) -> Result <usize > {
676
+ pub fn tee(
677
+ fd_in: RawFd ,
678
+ fd_out: RawFd ,
679
+ len: usize ,
680
+ flags: SpliceFFlags ,
681
+ ) -> Result <usize > {
641
682
let ret = unsafe { libc:: tee( fd_in, fd_out, len, flags. bits( ) ) } ;
642
683
Errno :: result( ret) . map( |r| r as usize )
643
684
}
@@ -646,9 +687,8 @@ pub fn tee(fd_in: RawFd, fd_out: RawFd, len: usize, flags: SpliceFFlags) -> Resu
646
687
pub fn vmsplice(
647
688
fd: RawFd ,
648
689
iov: & [ std:: io:: IoSlice <' _>] ,
649
- flags: SpliceFFlags
650
- ) -> Result <usize >
651
- {
690
+ flags: SpliceFFlags ,
691
+ ) -> Result <usize > {
652
692
let ret = unsafe {
653
693
libc:: vmsplice(
654
694
fd,
@@ -778,14 +818,19 @@ impl SpacectlRange {
778
818
/// ```
779
819
#[ cfg( target_os = "freebsd" ) ]
780
820
pub fn fspacectl( fd: RawFd , range: SpacectlRange ) -> Result <SpacectlRange > {
781
- let mut rqsr = libc:: spacectl_range{ r_offset: range. 0 , r_len: range. 1 } ;
782
- let res = unsafe { libc:: fspacectl(
821
+ let mut rqsr = libc:: spacectl_range {
822
+ r_offset: range. 0 ,
823
+ r_len: range. 1 ,
824
+ } ;
825
+ let res = unsafe {
826
+ libc:: fspacectl(
783
827
fd,
784
828
libc:: SPACECTL_DEALLOC , // Only one command is supported ATM
785
829
& rqsr,
786
- 0 , // No flags are currently supported
787
- & mut rqsr
788
- ) } ;
830
+ 0 , // No flags are currently supported
831
+ & mut rqsr,
832
+ )
833
+ } ;
789
834
Errno :: result( res) . map( |_| SpacectlRange ( rqsr. r_offset, rqsr. r_len) )
790
835
}
791
836
@@ -820,18 +865,25 @@ pub fn fspacectl(fd: RawFd, range: SpacectlRange) -> Result<SpacectlRange> {
820
865
/// assert_eq!(buf, b"012\0\0\0\0\0\09abcdef");
821
866
/// ```
822
867
#[ cfg( target_os = "freebsd" ) ]
823
- pub fn fspacectl_all( fd: RawFd , offset: libc:: off_t, len: libc:: off_t)
824
- -> Result <( ) >
825
- {
826
- let mut rqsr = libc:: spacectl_range{ r_offset: offset, r_len: len} ;
868
+ pub fn fspacectl_all(
869
+ fd: RawFd ,
870
+ offset: libc:: off_t,
871
+ len: libc:: off_t,
872
+ ) -> Result <( ) > {
873
+ let mut rqsr = libc:: spacectl_range {
874
+ r_offset: offset,
875
+ r_len: len,
876
+ } ;
827
877
while rqsr. r_len > 0 {
828
- let res = unsafe { libc:: fspacectl(
878
+ let res = unsafe {
879
+ libc:: fspacectl(
829
880
fd,
830
881
libc:: SPACECTL_DEALLOC , // Only one command is supported ATM
831
882
& rqsr,
832
- 0 , // No flags are currently supported
833
- & mut rqsr
834
- ) } ;
883
+ 0 , // No flags are currently supported
884
+ & mut rqsr,
885
+ )
886
+ } ;
835
887
Errno :: result( res) ?;
836
888
}
837
889
Ok ( ( ) )
@@ -848,8 +900,8 @@ pub fn fspacectl_all(fd: RawFd, offset: libc::off_t, len: libc::off_t)
848
900
) ) ]
849
901
mod posix_fadvise {
850
902
use crate :: errno:: Errno ;
851
- use std:: os:: unix:: io:: RawFd ;
852
903
use crate :: Result ;
904
+ use std:: os:: unix:: io:: RawFd ;
853
905
854
906
#[ cfg( feature = "fs" ) ]
855
907
libc_enum! {
@@ -894,7 +946,11 @@ mod posix_fadvise {
894
946
target_os = "wasi" ,
895
947
target_os = "freebsd"
896
948
) ) ]
897
- pub fn posix_fallocate( fd: RawFd , offset: libc:: off_t, len: libc:: off_t) -> Result <( ) > {
949
+ pub fn posix_fallocate(
950
+ fd: RawFd ,
951
+ offset: libc:: off_t,
952
+ len: libc:: off_t,
953
+ ) -> Result <( ) > {
898
954
let res = unsafe { libc:: posix_fallocate( fd, offset, len) } ;
899
955
match Errno :: result( res) {
900
956
Err ( err) => Err ( err) ,
0 commit comments