-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0002-std-xous-add-support-for-path.patch
113 lines (109 loc) · 3.13 KB
/
0002-std-xous-add-support-for-path.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
From db6490c1795a550addc99c72e352e1280385eaec Mon Sep 17 00:00:00 2001
From: Sean Cross <sean@osdyne.com>
Date: Tue, 6 Aug 2024 22:45:31 +0800
Subject: [PATCH 2/4] std: xous: add support for path
Add support for the Xous-specific path implementation.
Signed-off-by: Sean Cross <sean@osdyne.com>
---
library/std/src/sys/path/mod.rs | 3 ++
library/std/src/sys/path/xous.rs | 76 ++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)
create mode 100644 library/std/src/sys/path/xous.rs
diff --git a/library/std/src/sys/path/mod.rs b/library/std/src/sys/path/mod.rs
index 1fa4e80d678..9a08e6fc2c5 100644
--- a/library/std/src/sys/path/mod.rs
+++ b/library/std/src/sys/path/mod.rs
@@ -8,6 +8,9 @@
} else if #[cfg(target_os = "solid_asp3")] {
mod unsupported_backslash;
pub use unsupported_backslash::*;
+ } else if #[cfg(target_os = "xous")] {
+ mod xous;
+ pub use xous::*;
} else if #[cfg(target_os = "uefi")] {
mod uefi;
pub use uefi::*;
diff --git a/library/std/src/sys/path/xous.rs b/library/std/src/sys/path/xous.rs
new file mode 100644
index 00000000000..c1f6359b117
--- /dev/null
+++ b/library/std/src/sys/path/xous.rs
@@ -0,0 +1,76 @@
+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())
+}
+
+pub(crate) fn is_absolute(path: &Path) -> bool {
+ path.has_root() && path.prefix().is_some()
+}
+
+/// 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))
+}
--
2.47.0