Skip to content

Commit 6afc509

Browse files
committed
vxWorks: implement get_path() and get_mode() for File fmt::Debug
1 parent 46bf6ad commit 6afc509

File tree

1 file changed

+20
-6
lines changed
  • src/libstd/sys/vxworks

1 file changed

+20
-6
lines changed

src/libstd/sys/vxworks/fs.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,27 @@ impl FromInner<c_int> for File {
400400

401401
impl fmt::Debug for File {
402402
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)))
406412
}
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+
}
410424
}
411425

412426
let fd = self.0.raw();

0 commit comments

Comments
 (0)