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 Jan 7, 2024
1 parent 4c1f4db commit d7805b1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
9 changes: 9 additions & 0 deletions library/std/src/sys/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 = "";
}
2 changes: 0 additions & 2 deletions library/std/src/sys/xous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub mod alloc;
pub mod args;
#[path = "../unix/cmath.rs"]
pub mod cmath;
#[path = "../unsupported/env.rs"]
pub mod env;
pub mod fs;
#[path = "../unsupported/io.rs"]
Expand All @@ -14,7 +13,6 @@ pub mod net;
pub mod os;
#[path = "../unix/os_str.rs"]
pub mod os_str;
#[path = "../unix/path.rs"]
pub mod path;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
Expand Down
72 changes: 72 additions & 0 deletions library/std/src/sys/xous/path.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 d7805b1

Please sign in to comment.