Skip to content

Commit

Permalink
Take sys/vxworks/{fd,fs,io} from sys/unix instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Oct 16, 2020
1 parent 3f196dc commit 71bb1dc
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 909 deletions.
15 changes: 15 additions & 0 deletions library/std/src/os/vxworks/fs.rs
Expand Up @@ -26,10 +26,16 @@ pub trait MetadataExt {
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blksize(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blocks(&self) -> u64;
Expand Down Expand Up @@ -66,12 +72,21 @@ impl MetadataExt for Metadata {
fn st_atime(&self) -> i64 {
self.as_inner().as_inner().st_atime as i64
}
fn st_atime_nsec(&self) -> i64 {
0
}
fn st_mtime(&self) -> i64 {
self.as_inner().as_inner().st_mtime as i64
}
fn st_mtime_nsec(&self) -> i64 {
0
}
fn st_ctime(&self) -> i64 {
self.as_inner().as_inner().st_ctime as i64
}
fn st_ctime_nsec(&self) -> i64 {
0
}
fn st_blksize(&self) -> u64 {
self.as_inner().as_inner().st_blksize as u64
}
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/vxworks/raw.rs
Expand Up @@ -5,3 +5,6 @@ use crate::os::raw::c_ulong;

#[stable(feature = "pthread_t", since = "1.8.0")]
pub type pthread_t = c_ulong;

#[stable(feature = "raw_ext", since = "1.1.0")]
pub use libc::{blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, off_t, time_t};
7 changes: 7 additions & 0 deletions library/std/src/sys/unix/ext/fs.rs
Expand Up @@ -650,6 +650,9 @@ pub trait MetadataExt {
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn blocks(&self) -> u64;
#[cfg(target_os = "vxworks")]
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn attrib(&self) -> u8;
}

#[stable(feature = "metadata_ext", since = "1.1.0")]
Expand Down Expand Up @@ -702,6 +705,10 @@ impl MetadataExt for fs::Metadata {
fn blocks(&self) -> u64 {
self.st_blocks()
}
#[cfg(target_os = "vxworks")]
fn attrib(&self) -> u8 {
self.st_attrib()
}
}

/// Unix-specific extensions for [`fs::FileType`].
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/sys/unix/fd.rs
Expand Up @@ -200,7 +200,8 @@ impl FileDesc {
target_os = "l4re",
target_os = "linux",
target_os = "haiku",
target_os = "redox"
target_os = "redox",
target_os = "vxworks"
)))]
pub fn set_cloexec(&self) -> io::Result<()> {
unsafe {
Expand All @@ -217,7 +218,8 @@ impl FileDesc {
target_os = "l4re",
target_os = "linux",
target_os = "haiku",
target_os = "redox"
target_os = "redox",
target_os = "vxworks"
))]
pub fn set_cloexec(&self) -> io::Result<()> {
unsafe {
Expand Down
56 changes: 49 additions & 7 deletions library/std/src/sys/unix/fs.rs
Expand Up @@ -297,20 +297,38 @@ impl FileAttr {

#[cfg(not(target_os = "netbsd"))]
impl FileAttr {
#[cfg(not(target_os = "vxworks"))]
pub fn modified(&self) -> io::Result<SystemTime> {
Ok(SystemTime::from(libc::timespec {
tv_sec: self.stat.st_mtime as libc::time_t,
tv_nsec: self.stat.st_mtime_nsec as _,
}))
}

#[cfg(target_os = "vxworks")]
pub fn modified(&self) -> io::Result<SystemTime> {
Ok(SystemTime::from(libc::timespec {
tv_sec: self.stat.st_mtime as libc::time_t,
tv_nsec: 0,
}))
}

#[cfg(not(target_os = "vxworks"))]
pub fn accessed(&self) -> io::Result<SystemTime> {
Ok(SystemTime::from(libc::timespec {
tv_sec: self.stat.st_atime as libc::time_t,
tv_nsec: self.stat.st_atime_nsec as _,
}))
}

#[cfg(target_os = "vxworks")]
pub fn accessed(&self) -> io::Result<SystemTime> {
Ok(SystemTime::from(libc::timespec {
tv_sec: self.stat.st_atime as libc::time_t,
tv_nsec: 0,
}))
}

#[cfg(any(
target_os = "freebsd",
target_os = "openbsd",
Expand Down Expand Up @@ -535,12 +553,22 @@ impl DirEntry {
lstat(&self.path())
}

#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "haiku"))]
#[cfg(any(
target_os = "solaris",
target_os = "illumos",
target_os = "haiku",
target_os = "vxworks"
))]
pub fn file_type(&self) -> io::Result<FileType> {
lstat(&self.path()).map(|m| m.file_type())
}

#[cfg(not(any(target_os = "solaris", target_os = "illumos", target_os = "haiku")))]
#[cfg(not(any(
target_os = "solaris",
target_os = "illumos",
target_os = "haiku",
target_os = "vxworks"
)))]
pub fn file_type(&self) -> io::Result<FileType> {
match self.entry.d_type {
libc::DT_CHR => Ok(FileType { mode: libc::S_IFCHR }),
Expand All @@ -565,7 +593,8 @@ impl DirEntry {
target_os = "haiku",
target_os = "l4re",
target_os = "fuchsia",
target_os = "redox"
target_os = "redox",
target_os = "vxworks"
))]
pub fn ino(&self) -> u64 {
self.entry.d_ino as u64
Expand Down Expand Up @@ -603,7 +632,8 @@ impl DirEntry {
target_os = "linux",
target_os = "emscripten",
target_os = "l4re",
target_os = "haiku"
target_os = "haiku",
target_os = "vxworks"
))]
fn name_bytes(&self) -> &[u8] {
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() }
Expand Down Expand Up @@ -901,13 +931,25 @@ impl fmt::Debug for File {
Some(PathBuf::from(OsString::from_vec(buf)))
}

#[cfg(not(any(target_os = "linux", target_os = "macos")))]
#[cfg(target_os = "vxworks")]
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)))
}

#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))]
fn get_path(_fd: c_int) -> Option<PathBuf> {
// FIXME(#24570): implement this for other Unix platforms
None
}

#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "vxworks"))]
fn get_mode(fd: c_int) -> Option<(bool, bool)> {
let mode = unsafe { libc::fcntl(fd, libc::F_GETFL) };
if mode == -1 {
Expand All @@ -921,7 +963,7 @@ impl fmt::Debug for File {
}
}

#[cfg(not(any(target_os = "linux", target_os = "macos")))]
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))]
fn get_mode(_fd: c_int) -> Option<(bool, bool)> {
// FIXME(#24570): implement this for other Unix platforms
None
Expand Down

0 comments on commit 71bb1dc

Please sign in to comment.