Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vxWorks: implement get_path() and get_mode() for File fmt::Debug #65246

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/libstd/sys/vxworks/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
kennytm marked this conversation as resolved.
Show resolved Hide resolved
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();
Expand Down