@@ -9,6 +9,7 @@ use std::os::unix::io::FromRawFd;
9
9
use std:: os:: unix:: io:: OwnedFd ;
10
10
use std:: os:: unix:: io:: RawFd ;
11
11
12
+ use crate :: IntoPathFd ;
12
13
#[ cfg( feature = "fs" ) ]
13
14
use crate :: { sys:: stat:: Mode , NixPath , Result } ;
14
15
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
@@ -211,15 +212,15 @@ pub fn open<P: ?Sized + NixPath>(
211
212
// The conversion is not identical on all operating systems.
212
213
#[ allow( clippy:: useless_conversion) ]
213
214
#[ cfg( not( target_os = "redox" ) ) ]
214
- pub fn openat<Fd : AsFd , P : ?Sized + NixPath >(
215
- dirfd: & Fd ,
215
+ pub fn openat<Fd : IntoPathFd , P : ?Sized + NixPath >(
216
+ dirfd: Fd ,
216
217
path: & P ,
217
218
oflag: OFlag ,
218
219
mode: Mode ,
219
220
) -> Result <OwnedFd > {
220
221
let fd = path. with_nix_path( |cstr| unsafe {
221
222
libc:: openat(
222
- dirfd. as_fd ( ) . as_raw_fd ( ) ,
223
+ dirfd. as_raw_path_fd ( ) ,
223
224
cstr. as_ptr( ) ,
224
225
oflag. bits( ) ,
225
226
mode. bits( ) as c_uint,
@@ -230,18 +231,18 @@ pub fn openat<Fd: AsFd, P: ?Sized + NixPath>(
230
231
}
231
232
232
233
#[ cfg( not( target_os = "redox" ) ) ]
233
- pub fn renameat<Fd1 : AsFd , P1 : ?Sized + NixPath , Fd2 : AsFd , P2 : ?Sized + NixPath >(
234
- old_dirfd: & Fd1 ,
234
+ pub fn renameat<Fd1 : IntoPathFd , P1 : ?Sized + NixPath , Fd2 : IntoPathFd , P2 : ?Sized + NixPath >(
235
+ old_dirfd: Fd1 ,
235
236
old_path: & P1 ,
236
- new_dirfd: & Fd2 ,
237
+ new_dirfd: Fd2 ,
237
238
new_path: & P2 ,
238
239
) -> Result <( ) > {
239
240
let res = old_path. with_nix_path( |old_cstr| {
240
241
new_path. with_nix_path( |new_cstr| unsafe {
241
242
libc:: renameat(
242
- old_dirfd. as_fd ( ) . as_raw_fd ( ) ,
243
+ old_dirfd. as_raw_path_fd ( ) ,
243
244
old_cstr. as_ptr( ) ,
244
- new_dirfd. as_fd ( ) . as_raw_fd ( ) ,
245
+ new_dirfd. as_raw_path_fd ( ) ,
245
246
new_cstr. as_ptr( ) ,
246
247
)
247
248
} )
@@ -264,19 +265,19 @@ libc_bitflags! {
264
265
feature ! {
265
266
#![ feature = "fs" ]
266
267
#[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
267
- pub fn renameat2<Fd1 : AsFd , P1 : ?Sized + NixPath , Fd2 : AsFd , P2 : ?Sized + NixPath >(
268
- old_dirfd: & Fd1 ,
268
+ pub fn renameat2<Fd1 : IntoPathFd , P1 : ?Sized + NixPath , Fd2 : IntoPathFd , P2 : ?Sized + NixPath >(
269
+ old_dirfd: Fd1 ,
269
270
old_path: & P1 ,
270
- new_dirfd: & Fd2 ,
271
+ new_dirfd: Fd2 ,
271
272
new_path: & P2 ,
272
273
flags: RenameFlags ,
273
274
) -> Result <( ) > {
274
275
let res = old_path. with_nix_path( |old_cstr| {
275
276
new_path. with_nix_path( |new_cstr| unsafe {
276
277
libc:: renameat2(
277
- old_dirfd. as_fd ( ) . as_raw_fd ( ) ,
278
+ old_dirfd. as_raw_path_fd ( ) ,
278
279
old_cstr. as_ptr( ) ,
279
- new_dirfd. as_fd ( ) . as_raw_fd ( ) ,
280
+ new_dirfd. as_raw_path_fd ( ) ,
280
281
new_cstr. as_ptr( ) ,
281
282
flags. bits( ) ,
282
283
)
@@ -404,10 +405,10 @@ pub fn readlink<P: ?Sized + NixPath>(path: &P) -> Result<OsString> {
404
405
405
406
#[ cfg( not( target_os = "redox" ) ) ]
406
407
pub fn readlinkat<Fd : AsFd , P : ?Sized + NixPath >(
407
- dirfd: & Fd ,
408
+ dirfd: Fd ,
408
409
path: & P ,
409
410
) -> Result <OsString > {
410
- inner_readlink( Some ( dirfd) , path)
411
+ inner_readlink( Some ( & dirfd) , path)
411
412
}
412
413
}
413
414
@@ -599,9 +600,9 @@ feature! {
599
600
/// returned.
600
601
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
601
602
pub fn copy_file_range<Fd1 : AsFd , Fd2 : AsFd >(
602
- fd_in: & Fd1 ,
603
+ fd_in: Fd1 ,
603
604
off_in: Option <& mut libc:: loff_t>,
604
- fd_out: & Fd2 ,
605
+ fd_out: Fd2 ,
605
606
off_out: Option <& mut libc:: loff_t>,
606
607
len: usize ,
607
608
) -> Result <usize > {
@@ -628,9 +629,9 @@ pub fn copy_file_range<Fd1: AsFd, Fd2: AsFd>(
628
629
629
630
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
630
631
pub fn splice<Fd1 : AsFd , Fd2 : AsFd >(
631
- fd_in: & Fd1 ,
632
+ fd_in: Fd1 ,
632
633
off_in: Option <& mut libc:: loff_t>,
633
- fd_out: & Fd2 ,
634
+ fd_out: Fd2 ,
634
635
off_out: Option <& mut libc:: loff_t>,
635
636
len: usize ,
636
637
flags: SpliceFFlags ,
@@ -657,8 +658,8 @@ pub fn splice<Fd1: AsFd, Fd2: AsFd>(
657
658
658
659
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
659
660
pub fn tee<Fd1 : AsFd , Fd2 : AsFd >(
660
- fd_in: & Fd1 ,
661
- fd_out: & Fd2 ,
661
+ fd_in: Fd1 ,
662
+ fd_out: Fd2 ,
662
663
len: usize ,
663
664
flags: SpliceFFlags ,
664
665
) -> Result <usize > {
@@ -675,7 +676,7 @@ pub fn tee<Fd1: AsFd, Fd2: AsFd>(
675
676
676
677
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
677
678
pub fn vmsplice<Fd : AsFd >(
678
- fd: & Fd ,
679
+ fd: Fd ,
679
680
iov: & [ std:: io:: IoSlice <' _>] ,
680
681
flags: SpliceFFlags ,
681
682
) -> Result <usize > {
@@ -734,7 +735,7 @@ feature! {
734
735
#[ cfg( any( target_os = "linux" ) ) ]
735
736
#[ cfg( feature = "fs" ) ]
736
737
pub fn fallocate<Fd : AsFd >(
737
- fd: & Fd ,
738
+ fd: Fd ,
738
739
mode: FallocateFlags ,
739
740
offset: libc:: off_t,
740
741
len: libc:: off_t,
@@ -810,7 +811,7 @@ impl SpacectlRange {
810
811
/// ```
811
812
#[ cfg( target_os = "freebsd" ) ]
812
813
pub fn fspacectl<Fd : AsFd >(
813
- fd: & Fd ,
814
+ fd: Fd ,
814
815
range: SpacectlRange ,
815
816
) -> Result <SpacectlRange > {
816
817
let mut rqsr = libc:: spacectl_range {
@@ -861,7 +862,7 @@ pub fn fspacectl<Fd: AsFd>(
861
862
/// ```
862
863
#[ cfg( target_os = "freebsd" ) ]
863
864
pub fn fspacectl_all<Fd : AsFd >(
864
- fd: & Fd ,
865
+ fd: Fd ,
865
866
offset: libc:: off_t,
866
867
len: libc:: off_t,
867
868
) -> Result <( ) > {
@@ -917,7 +918,7 @@ mod posix_fadvise {
917
918
feature! {
918
919
#![ feature = "fs" ]
919
920
pub fn posix_fadvise<Fd : AsFd >(
920
- fd: & Fd ,
921
+ fd: Fd ,
921
922
offset: libc:: off_t,
922
923
len: libc:: off_t,
923
924
advice: PosixFadviseAdvice ,
@@ -950,7 +951,7 @@ mod posix_fadvise {
950
951
target_os = "freebsd"
951
952
) ) ]
952
953
pub fn posix_fallocate<Fd : AsFd >(
953
- fd: & Fd ,
954
+ fd: Fd ,
954
955
offset: libc:: off_t,
955
956
len: libc:: off_t,
956
957
) -> Result <( ) > {
0 commit comments