@@ -6,6 +6,13 @@ use std::os::raw;
6
6
use std:: os:: unix:: ffi:: OsStringExt ;
7
7
use std:: os:: unix:: io:: RawFd ;
8
8
// For splice and copy_file_range
9
+ #[ cfg( any(
10
+ target_os = "netbsd" ,
11
+ target_os = "macos" ,
12
+ target_os = "ios" ,
13
+ target_os = "dragonfly" ,
14
+ ) ) ]
15
+ use std:: path:: PathBuf ;
9
16
#[ cfg( any(
10
17
target_os = "android" ,
11
18
target_os = "freebsd" ,
@@ -489,8 +496,8 @@ pub enum FcntlArg<'a> {
489
496
F_GETPIPE_SZ ,
490
497
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
491
498
F_SETPIPE_SZ ( c_int) ,
492
- #[ cfg( any( target_os = "netbsd" , target_os = "macos" , target_os = "ios" ) ) ]
493
- F_GETPATH ( Vec < u8 > ) ,
499
+ #[ cfg( any( target_os = "netbsd" , target_os = "dragonfly" , target_os = " macos", target_os = "ios" ) ) ]
500
+ F_GETPATH ( & ' a mut PathBuf ) ,
494
501
// TODO: Rest of flags
495
502
}
496
503
@@ -551,10 +558,16 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
551
558
F_GETPIPE_SZ => libc:: fcntl( fd, libc:: F_GETPIPE_SZ ) ,
552
559
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
553
560
F_SETPIPE_SZ ( size) => libc:: fcntl( fd, libc:: F_SETPIPE_SZ , size) ,
554
- #[ cfg( any( target_os = "netbsd" , target_os = "macos" , target_os = "ios" ) ) ]
561
+ #[ cfg( any( target_os = "dragonfly" , target_os = " netbsd", target_os = "macos" , target_os = "ios" ) ) ]
555
562
F_GETPATH ( path) => {
556
- path. resize( libc:: PATH_MAX ) ;
557
- libc:: fcntl( fd, libc:: F_GETPATH , path. as_ptr( ) )
563
+ let mut buffer = vec![ 0 ; libc:: PATH_MAX as usize ] ;
564
+ let res = libc:: fcntl( fd, libc:: F_GETPATH , buffer. as_ptr( ) ) ;
565
+ let ok_res = Errno :: result( res) ?;
566
+ let len = buffer. iter( ) . position( |b| * b == 0 ) . unwrap( ) ;
567
+ buffer. truncate( len as usize ) ;
568
+ buffer. shrink_to_fit( ) ;
569
+ * path = PathBuf :: from( OsString :: from_vec( buffer) ) ;
570
+ ok_res
558
571
} ,
559
572
}
560
573
} ;
0 commit comments