diff options
| author | BaoshanPang <pangbw@gmail.com> | 2019-10-09 09:10:24 -0700 |
|---|---|---|
| committer | BaoshanPang <pangbw@gmail.com> | 2019-10-10 08:41:10 -0700 |
| commit | 6afc5091b91c357285f224564d9f8416f52041b1 (patch) | |
| tree | 122f1010766bff98fa490dae955c2b0b1a7f8699 /src/libstd/sys | |
| parent | 46bf6ad416cf922c410fed11e9f73c03c0015bcd (diff) | |
| download | rust-6afc5091b91c357285f224564d9f8416f52041b1.tar.gz rust-6afc5091b91c357285f224564d9f8416f52041b1.zip | |
vxWorks: implement get_path() and get_mode() for File fmt::Debug
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/vxworks/fs.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/libstd/sys/vxworks/fs.rs b/src/libstd/sys/vxworks/fs.rs index 51fdb1c0e55..adb08d8005a 100644 --- a/src/libstd/sys/vxworks/fs.rs +++ b/src/libstd/sys/vxworks/fs.rs @@ -400,13 +400,27 @@ impl FromInner<c_int> for File { impl fmt::Debug for File { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fn get_path(_fd: c_int) -> Option<PathBuf> { - // FIXME(#:(): implement this for VxWorks - None + fn get_path(fd: c_int) -> Option<PathBuf> { + let mut buf = vec![0;libc::PATH_MAX as usize]; + let n = unsafe { libc::ioctl(fd, libc::FIOGETNAME, buf.as_ptr()) }; + if n == -1 { + return None; + } + let l = buf.iter().position(|&c| c == 0).unwrap(); + buf.truncate(l as usize); + Some(PathBuf::from(OsString::from_vec(buf))) } - fn get_mode(_fd: c_int) -> Option<(bool, bool)> { - // FIXME(#:(): implement this for VxWorks - None + fn get_mode(fd: c_int) -> Option<(bool, bool)> { + let mode = unsafe { libc::fcntl(fd, libc::F_GETFL) }; + if mode == -1 { + return None; + } + match mode & libc::O_ACCMODE { + libc::O_RDONLY => Some((true, false)), + libc::O_RDWR => Some((true, true)), + libc::O_WRONLY => Some((false, true)), + _ => None + } } let fd = self.0.raw(); |
