Skip to content

Commit

Permalink
Take sys/vxworks/{os,path,pipe} 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 71bb1dc commit 408db0d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 446 deletions.
35 changes: 30 additions & 5 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cfg_if::cfg_if! {
}

extern "C" {
#[cfg(not(target_os = "dragonfly"))]
#[cfg(not(any(target_os = "dragonfly", target_os = "vxworks")))]
#[cfg_attr(
any(
target_os = "linux",
Expand Down Expand Up @@ -67,18 +67,28 @@ extern "C" {
}

/// Returns the platform-specific value of errno
#[cfg(not(target_os = "dragonfly"))]
#[cfg(not(any(target_os = "dragonfly", target_os = "vxworks")))]
pub fn errno() -> i32 {
unsafe { (*errno_location()) as i32 }
}

/// Sets the platform-specific value of errno
#[cfg(all(not(target_os = "linux"), not(target_os = "dragonfly")))] // needed for readdir and syscall!
#[cfg(all(not(target_os = "linux"), not(target_os = "dragonfly"), not(target_os = "vxworks")))] // needed for readdir and syscall!
#[allow(dead_code)] // but not all target cfgs actually end up using it
pub fn set_errno(e: i32) {
unsafe { *errno_location() = e as c_int }
}

#[cfg(target_os = "vxworks")]
pub fn errno() -> i32 {
unsafe { libc::errnoGet() }
}

#[cfg(target_os = "vxworks")]
pub fn set_errno(e: i32) {
unsafe { libc::errnoSet(e as c_int) };
}

#[cfg(target_os = "dragonfly")]
pub fn errno() -> i32 {
extern "C" {
Expand Down Expand Up @@ -439,6 +449,19 @@ pub fn current_exe() -> io::Result<PathBuf> {
Err(io::Error::new(ErrorKind::Other, "Not yet implemented!"))
}

#[cfg(target_os = "vxworks")]
pub fn current_exe() -> io::Result<PathBuf> {
#[cfg(test)]
use realstd::env;

#[cfg(not(test))]
use crate::env;

let exe_path = env::args().next().unwrap();
let path = path::Path::new(&exe_path);
path.canonicalize()
}

pub struct Env {
iter: vec::IntoIter<(OsString, OsString)>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
Expand Down Expand Up @@ -568,7 +591,8 @@ pub fn home_dir() -> Option<PathBuf> {
target_os = "android",
target_os = "ios",
target_os = "emscripten",
target_os = "redox"
target_os = "redox",
target_os = "vxworks"
))]
unsafe fn fallback() -> Option<OsString> {
None
Expand All @@ -577,7 +601,8 @@ pub fn home_dir() -> Option<PathBuf> {
target_os = "android",
target_os = "ios",
target_os = "emscripten",
target_os = "redox"
target_os = "redox",
target_os = "vxworks"
)))]
unsafe fn fallback() -> Option<OsString> {
let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/sys/vxworks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ pub mod memchr;
pub mod mutex;
#[path = "../unix/net.rs"]
pub mod net;
#[path = "../unix/os.rs"]
pub mod os;
#[path = "../unix/path.rs"]
pub mod path;
#[path = "../unix/pipe.rs"]
pub mod pipe;
pub mod process;
pub mod rand;
Expand Down
Loading

0 comments on commit 408db0d

Please sign in to comment.