@@ -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 PathBuf ) ,
494
501
// TODO: Rest of flags
495
502
}
496
503
@@ -553,8 +560,17 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
553
560
F_SETPIPE_SZ ( size) => libc:: fcntl( fd, libc:: F_SETPIPE_SZ , size) ,
554
561
#[ cfg( any( 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 r = libc:: fcntl( fd, libc:: F_GETPATH , buffer. as_ptr( ) ) ;
565
+ if r < 0 {
566
+ return Errno :: result( r) ;
567
+ } else {
568
+ let len = buffer. iter( ) . position( |b| * b == 0 ) . unwrap( ) ;
569
+ buffer. truncate( len as usize ) ;
570
+ buffer. shrink_to_fit( ) ;
571
+ * path = PathBuf :: from( OsString :: from_vec( buffer) ) ;
572
+ return r;
573
+ }
558
574
} ,
559
575
}
560
576
} ;
0 commit comments