@@ -15,6 +15,13 @@ use std::{
15
15
os:: unix:: io:: { AsFd , AsRawFd } ,
16
16
ptr,
17
17
} ;
18
+ #[ cfg( any(
19
+ target_os = "netbsd" ,
20
+ target_os = "macos" ,
21
+ target_os = "ios" ,
22
+ target_os = "dragonfly" ,
23
+ ) ) ]
24
+ use std:: path:: PathBuf ;
18
25
19
26
#[ cfg( feature = "fs" ) ]
20
27
use crate :: { sys:: stat:: Mode , NixPath , Result } ;
@@ -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,16 @@ 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
+ }
558
573
} ,
559
574
}
560
575
} ;
0 commit comments