1
1
use crate :: errno:: Errno ;
2
+ #[ cfg( all( target_os = "freebsd" , target_arch = "x86_64" ) ) ]
3
+ use core:: slice;
2
4
use libc:: { self , c_int, c_uint, size_t, ssize_t} ;
3
5
#[ cfg( any(
4
6
target_os = "netbsd" ,
5
7
target_os = "macos" ,
6
8
target_os = "ios" ,
7
9
target_os = "dragonfly" ,
10
+ all( target_os = "freebsd" , target_arch = "x86_64" ) ,
8
11
) ) ]
9
12
use std:: ffi:: CStr ;
10
13
use std:: ffi:: OsString ;
@@ -18,6 +21,7 @@ use std::os::unix::io::RawFd;
18
21
target_os = "macos" ,
19
22
target_os = "ios" ,
20
23
target_os = "dragonfly" ,
24
+ all( target_os = "freebsd" , target_arch = "x86_64" ) ,
21
25
) ) ]
22
26
use std:: path:: PathBuf ;
23
27
#[ cfg( any(
@@ -505,6 +509,8 @@ pub enum FcntlArg<'a> {
505
509
F_SETPIPE_SZ ( c_int) ,
506
510
#[ cfg( any( target_os = "netbsd" , target_os = "dragonfly" , target_os = "macos" , target_os = "ios" ) ) ]
507
511
F_GETPATH ( & ' a mut PathBuf ) ,
512
+ #[ cfg( all( target_os = "freebsd" , target_arch = "x86_64" ) ) ]
513
+ F_KINFO ( & ' a mut PathBuf ) ,
508
514
// TODO: Rest of flags
509
515
}
510
516
@@ -574,6 +580,18 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
574
580
* path = PathBuf :: from( OsString :: from( optr. to_str( ) . unwrap( ) ) ) ;
575
581
return Ok ( ok_res)
576
582
} ,
583
+ #[ cfg( all( target_os = "freebsd" , target_arch = "x86_64" ) ) ]
584
+ F_KINFO ( path) => {
585
+ let mut info: libc:: kinfo_file = std:: mem:: zeroed( ) ;
586
+ info. kf_structsize = std:: mem:: size_of:: <libc:: kinfo_file>( ) as i32 ;
587
+ let res = libc:: fcntl( fd, libc:: F_KINFO , & mut info) ;
588
+ let ok_res = Errno :: result( res) ?;
589
+ let p = info. kf_path;
590
+ let u8_slice = slice:: from_raw_parts( p. as_ptr( ) . cast( ) , p. len( ) ) ;
591
+ let optr = CStr :: from_bytes_until_nul( u8_slice) . unwrap( ) ;
592
+ * path = PathBuf :: from( OsString :: from( optr. to_str( ) . unwrap( ) ) ) ;
593
+ return Ok ( ok_res)
594
+ } ,
577
595
}
578
596
} ;
579
597
0 commit comments