Skip to content

Commit 71bb1dc

Browse files
committed
Take sys/vxworks/{fd,fs,io} from sys/unix instead.
1 parent 3f196dc commit 71bb1dc

File tree

9 files changed

+81
-909
lines changed

9 files changed

+81
-909
lines changed

library/std/src/os/vxworks/fs.rs

+15
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ pub trait MetadataExt {
2626
#[stable(feature = "metadata_ext2", since = "1.8.0")]
2727
fn st_atime(&self) -> i64;
2828
#[stable(feature = "metadata_ext2", since = "1.8.0")]
29+
fn st_atime_nsec(&self) -> i64;
30+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
2931
fn st_mtime(&self) -> i64;
3032
#[stable(feature = "metadata_ext2", since = "1.8.0")]
33+
fn st_mtime_nsec(&self) -> i64;
34+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
3135
fn st_ctime(&self) -> i64;
3236
#[stable(feature = "metadata_ext2", since = "1.8.0")]
37+
fn st_ctime_nsec(&self) -> i64;
38+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
3339
fn st_blksize(&self) -> u64;
3440
#[stable(feature = "metadata_ext2", since = "1.8.0")]
3541
fn st_blocks(&self) -> u64;
@@ -66,12 +72,21 @@ impl MetadataExt for Metadata {
6672
fn st_atime(&self) -> i64 {
6773
self.as_inner().as_inner().st_atime as i64
6874
}
75+
fn st_atime_nsec(&self) -> i64 {
76+
0
77+
}
6978
fn st_mtime(&self) -> i64 {
7079
self.as_inner().as_inner().st_mtime as i64
7180
}
81+
fn st_mtime_nsec(&self) -> i64 {
82+
0
83+
}
7284
fn st_ctime(&self) -> i64 {
7385
self.as_inner().as_inner().st_ctime as i64
7486
}
87+
fn st_ctime_nsec(&self) -> i64 {
88+
0
89+
}
7590
fn st_blksize(&self) -> u64 {
7691
self.as_inner().as_inner().st_blksize as u64
7792
}

library/std/src/os/vxworks/raw.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ use crate::os::raw::c_ulong;
55

66
#[stable(feature = "pthread_t", since = "1.8.0")]
77
pub type pthread_t = c_ulong;
8+
9+
#[stable(feature = "raw_ext", since = "1.1.0")]
10+
pub use libc::{blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, off_t, time_t};

library/std/src/sys/unix/ext/fs.rs

+7
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,9 @@ pub trait MetadataExt {
650650
/// ```
651651
#[stable(feature = "metadata_ext", since = "1.1.0")]
652652
fn blocks(&self) -> u64;
653+
#[cfg(target_os = "vxworks")]
654+
#[stable(feature = "metadata_ext", since = "1.1.0")]
655+
fn attrib(&self) -> u8;
653656
}
654657

655658
#[stable(feature = "metadata_ext", since = "1.1.0")]
@@ -702,6 +705,10 @@ impl MetadataExt for fs::Metadata {
702705
fn blocks(&self) -> u64 {
703706
self.st_blocks()
704707
}
708+
#[cfg(target_os = "vxworks")]
709+
fn attrib(&self) -> u8 {
710+
self.st_attrib()
711+
}
705712
}
706713

707714
/// Unix-specific extensions for [`fs::FileType`].

library/std/src/sys/unix/fd.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ impl FileDesc {
200200
target_os = "l4re",
201201
target_os = "linux",
202202
target_os = "haiku",
203-
target_os = "redox"
203+
target_os = "redox",
204+
target_os = "vxworks"
204205
)))]
205206
pub fn set_cloexec(&self) -> io::Result<()> {
206207
unsafe {
@@ -217,7 +218,8 @@ impl FileDesc {
217218
target_os = "l4re",
218219
target_os = "linux",
219220
target_os = "haiku",
220-
target_os = "redox"
221+
target_os = "redox",
222+
target_os = "vxworks"
221223
))]
222224
pub fn set_cloexec(&self) -> io::Result<()> {
223225
unsafe {

library/std/src/sys/unix/fs.rs

+49-7
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,38 @@ impl FileAttr {
297297

298298
#[cfg(not(target_os = "netbsd"))]
299299
impl FileAttr {
300+
#[cfg(not(target_os = "vxworks"))]
300301
pub fn modified(&self) -> io::Result<SystemTime> {
301302
Ok(SystemTime::from(libc::timespec {
302303
tv_sec: self.stat.st_mtime as libc::time_t,
303304
tv_nsec: self.stat.st_mtime_nsec as _,
304305
}))
305306
}
306307

308+
#[cfg(target_os = "vxworks")]
309+
pub fn modified(&self) -> io::Result<SystemTime> {
310+
Ok(SystemTime::from(libc::timespec {
311+
tv_sec: self.stat.st_mtime as libc::time_t,
312+
tv_nsec: 0,
313+
}))
314+
}
315+
316+
#[cfg(not(target_os = "vxworks"))]
307317
pub fn accessed(&self) -> io::Result<SystemTime> {
308318
Ok(SystemTime::from(libc::timespec {
309319
tv_sec: self.stat.st_atime as libc::time_t,
310320
tv_nsec: self.stat.st_atime_nsec as _,
311321
}))
312322
}
313323

324+
#[cfg(target_os = "vxworks")]
325+
pub fn accessed(&self) -> io::Result<SystemTime> {
326+
Ok(SystemTime::from(libc::timespec {
327+
tv_sec: self.stat.st_atime as libc::time_t,
328+
tv_nsec: 0,
329+
}))
330+
}
331+
314332
#[cfg(any(
315333
target_os = "freebsd",
316334
target_os = "openbsd",
@@ -535,12 +553,22 @@ impl DirEntry {
535553
lstat(&self.path())
536554
}
537555

538-
#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "haiku"))]
556+
#[cfg(any(
557+
target_os = "solaris",
558+
target_os = "illumos",
559+
target_os = "haiku",
560+
target_os = "vxworks"
561+
))]
539562
pub fn file_type(&self) -> io::Result<FileType> {
540563
lstat(&self.path()).map(|m| m.file_type())
541564
}
542565

543-
#[cfg(not(any(target_os = "solaris", target_os = "illumos", target_os = "haiku")))]
566+
#[cfg(not(any(
567+
target_os = "solaris",
568+
target_os = "illumos",
569+
target_os = "haiku",
570+
target_os = "vxworks"
571+
)))]
544572
pub fn file_type(&self) -> io::Result<FileType> {
545573
match self.entry.d_type {
546574
libc::DT_CHR => Ok(FileType { mode: libc::S_IFCHR }),
@@ -565,7 +593,8 @@ impl DirEntry {
565593
target_os = "haiku",
566594
target_os = "l4re",
567595
target_os = "fuchsia",
568-
target_os = "redox"
596+
target_os = "redox",
597+
target_os = "vxworks"
569598
))]
570599
pub fn ino(&self) -> u64 {
571600
self.entry.d_ino as u64
@@ -603,7 +632,8 @@ impl DirEntry {
603632
target_os = "linux",
604633
target_os = "emscripten",
605634
target_os = "l4re",
606-
target_os = "haiku"
635+
target_os = "haiku",
636+
target_os = "vxworks"
607637
))]
608638
fn name_bytes(&self) -> &[u8] {
609639
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() }
@@ -901,13 +931,25 @@ impl fmt::Debug for File {
901931
Some(PathBuf::from(OsString::from_vec(buf)))
902932
}
903933

904-
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
934+
#[cfg(target_os = "vxworks")]
935+
fn get_path(fd: c_int) -> Option<PathBuf> {
936+
let mut buf = vec![0; libc::PATH_MAX as usize];
937+
let n = unsafe { libc::ioctl(fd, libc::FIOGETNAME, buf.as_ptr()) };
938+
if n == -1 {
939+
return None;
940+
}
941+
let l = buf.iter().position(|&c| c == 0).unwrap();
942+
buf.truncate(l as usize);
943+
Some(PathBuf::from(OsString::from_vec(buf)))
944+
}
945+
946+
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))]
905947
fn get_path(_fd: c_int) -> Option<PathBuf> {
906948
// FIXME(#24570): implement this for other Unix platforms
907949
None
908950
}
909951

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

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

0 commit comments

Comments
 (0)