File tree 1 file changed +20
-6
lines changed
1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -400,13 +400,27 @@ impl FromInner<c_int> for File {
400
400
401
401
impl fmt:: Debug for File {
402
402
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
403
- fn get_path ( _fd : c_int ) -> Option < PathBuf > {
404
- // FIXME(#:(): implement this for VxWorks
405
- None
403
+ fn get_path ( fd : c_int ) -> Option < PathBuf > {
404
+ let mut buf = vec ! [ 0 ; libc:: PATH_MAX as usize ] ;
405
+ let n = unsafe { libc:: ioctl ( fd, libc:: FIOGETNAME , buf. as_ptr ( ) ) } ;
406
+ if n == -1 {
407
+ return None ;
408
+ }
409
+ let l = buf. iter ( ) . position ( |& c| c == 0 ) . unwrap ( ) ;
410
+ buf. truncate ( l as usize ) ;
411
+ Some ( PathBuf :: from ( OsString :: from_vec ( buf) ) )
406
412
}
407
- fn get_mode ( _fd : c_int ) -> Option < ( bool , bool ) > {
408
- // FIXME(#:(): implement this for VxWorks
409
- None
413
+ fn get_mode ( fd : c_int ) -> Option < ( bool , bool ) > {
414
+ let mode = unsafe { libc:: fcntl ( fd, libc:: F_GETFL ) } ;
415
+ if mode == -1 {
416
+ return None ;
417
+ }
418
+ match mode & libc:: O_ACCMODE {
419
+ libc:: O_RDONLY => Some ( ( true , false ) ) ,
420
+ libc:: O_RDWR => Some ( ( true , true ) ) ,
421
+ libc:: O_WRONLY => Some ( ( false , true ) ) ,
422
+ _ => None
423
+ }
410
424
}
411
425
412
426
let fd = self . 0 . raw ( ) ;
You can’t perform that action at this time.
0 commit comments