Skip to content

Commit

Permalink
xous: add env and path files
Browse files Browse the repository at this point in the history
Add initial support for `env` and `Path`. Note that this is still using
the separator of `:`.

Signed-off-by: Sean Cross <[email protected]>
  • Loading branch information
xobs committed May 2, 2024
1 parent 79314ad commit 9df3977
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
9 changes: 9 additions & 0 deletions library/std/src/sys/pal/xous/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod os {
pub const FAMILY: &str = "";
pub const OS: &str = "xous";
pub const DLL_PREFIX: &str = "";
pub const DLL_SUFFIX: &str = "";
pub const DLL_EXTENSION: &str = "";
pub const EXE_SUFFIX: &str = "";
pub const EXE_EXTENSION: &str = "";
}
1 change: 0 additions & 1 deletion library/std/src/sys/pal/xous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pub mod alloc;
pub mod args;
#[path = "../unsupported/env.rs"]
pub mod env;
pub mod fs;
#[path = "../unsupported/io.rs"]
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/sys/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ cfg_if::cfg_if! {
))] {
mod unsupported_backslash;
pub use unsupported_backslash::*;
} else if #[cfg(target_os = "xous")] {
mod xous;
pub use xous::*;
} else {
mod unix;
pub use unix::*;
Expand Down
72 changes: 72 additions & 0 deletions library/std/src/sys/path/xous.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use crate::ffi::OsStr;
use crate::io;
use crate::path::{Path, PathBuf, Prefix};

#[inline]
pub fn is_sep_byte(b: u8) -> bool {
b == b':'
}

#[inline]
pub fn is_verbatim_sep(b: u8) -> bool {
b == b':'
}

#[inline]
pub fn parse_prefix(_: &OsStr) -> Option<Prefix<'_>> {
None
}

pub const MAIN_SEP_STR: &str = ":";
pub const MAIN_SEP: char = ':';

/// Make a POSIX path absolute without changing its semantics.
pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
Ok(path.to_owned())
}

/// Split a path into its constituant Basis and Dict, if the path is legal.
pub(crate) fn split_basis_and_dict<'a, F: Fn() -> Option<&'a str>>(
src: &'a str,
default: F,
) -> Result<(Option<&'a str>, Option<&'a str>), ()> {
let mut basis = None;
let dict;
if let Some(src) = src.strip_prefix(crate::path::MAIN_SEPARATOR) {
if let Some((maybe_basis, maybe_dict)) = src.split_once(crate::path::MAIN_SEPARATOR) {
if !maybe_basis.is_empty() {
basis = Some(maybe_basis);
} else {
basis = default();
}

if maybe_dict.is_empty() {
dict = None;
} else {
dict = Some(maybe_dict);
}
} else {
if !src.is_empty() {
basis = Some(src);
}
dict = None;
}
} else {
if src.is_empty() {
return Ok((basis, Some("")));
}
dict = Some(src);
}

if let Some(basis) = &basis {
if basis.ends_with(crate::path::MAIN_SEPARATOR) {
return Err(());
}
}
if let Some(dict) = &dict {
if dict.ends_with(crate::path::MAIN_SEPARATOR) {
return Err(());
}
}
Ok((basis, dict))
}

0 comments on commit 9df3977

Please sign in to comment.