about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-10-13 19:17:06 +0200
committerGitHub <noreply@github.com>2019-10-13 19:17:06 +0200
commit2a9c79107696580c703d015ebc8aab008da82899 (patch)
treea03ec081b857c73435df01b28dfb6847165ae358 /src/libstd
parent7c20a8ddb8efd3998dc4de049ff69e3161a01788 (diff)
parent6afc5091b91c357285f224564d9f8416f52041b1 (diff)
downloadrust-2a9c79107696580c703d015ebc8aab008da82899.tar.gz
rust-2a9c79107696580c703d015ebc8aab008da82899.zip
Rollup merge of #65246 - Wind-River:real_master_2, r=kennytm
vxWorks: implement get_path() and get_mode() for File fmt::Debug
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sys/vxworks/fs.rs26
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();