Skip to content
Snippets Groups Projects
Commit ab3ececc authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'scheme-fmt' into 'master'

Scheme fmt

See merge request redox-os/relibc!451
parents 83e4095e 7eefdaf4
No related branches found
No related tags found
1 merge request!451Scheme fmt
Pipeline #14087 passed
......@@ -10,9 +10,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "2.4.1"
version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
[[package]]
name = "cbitset"
......@@ -198,6 +198,12 @@ dependencies = [
"redox_syscall",
]
[[package]]
name = "redox-path"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f45c7275fe1467ea17542c01766ae9872fa98aa7fe06ba5ea6595f7a9f0699c6"
[[package]]
name = "redox_syscall"
version = "0.4.1"
......@@ -224,6 +230,7 @@ dependencies = [
"rand_jitter",
"rand_xorshift",
"redox-exec",
"redox-path",
"redox_syscall",
"sc",
"unicode-width",
......
......@@ -9,7 +9,13 @@ name = "relibc"
crate-type = ["staticlib"]
[workspace]
members = ["src/crt0", "src/crti", "src/crtn", "src/ld_so", "src/platform/redox/redox-exec"]
members = [
"src/crt0",
"src/crti",
"src/crtn",
"src/ld_so",
"src/platform/redox/redox-exec",
]
exclude = ["tests", "dlmalloc-rs"]
[build-dependencies]
......@@ -47,6 +53,7 @@ sc = "0.2.3"
[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.4"
redox-exec = { path = "src/platform/redox/redox-exec" }
redox-path = "0.1"
[features]
default = ["check_against_libc_crate"]
......
use syscall::{data::Stat, error::*, flag::*};
use alloc::{borrow::ToOwned, boxed::Box, string::String, vec::Vec};
use syscall::{data::Stat, error::*, flag::*};
use super::{libcscheme, FdGuard};
use crate::sync::Mutex;
pub use redox_path::canonicalize_using_cwd;
// TODO: Define in syscall
const PATH_MAX: usize = 4096;
/// Make a relative path absolute.
///
/// Given a cwd of "scheme:/path", this his function will turn "foo" into "scheme:/path/foo".
/// "/foo" will turn into "scheme:/foo". "bar:/foo" will be used directly, as it is already
/// absolute
pub fn canonicalize_using_cwd<'a>(cwd_opt: Option<&str>, path: &'a str) -> Option<String> {
let mut canon = if path.find(':').is_none() {
let cwd = cwd_opt?;
let path_start = cwd.find(':')? + 1;
let mut canon = if !path.starts_with('/') {
let mut c = cwd.to_owned();
if !c.ends_with('/') {
c.push('/');
}
c
} else {
cwd[..path_start].to_owned()
};
canon.push_str(&path);
canon
} else {
path.to_owned()
};
// NOTE: assumes the scheme does not include anything like "../" or "./"
let mut result = {
let parts = canon
.split('/')
.rev()
.scan(0, |nskip, part| {
if part == "." {
Some(None)
} else if part == ".." {
*nskip += 1;
Some(None)
} else if *nskip > 0 {
*nskip -= 1;
Some(None)
} else {
Some(Some(part))
}
})
.filter_map(|x| x)
.filter(|x| !x.is_empty())
.collect::<Vec<_>>();
parts.iter().rev().fold(String::new(), |mut string, &part| {
string.push_str(part);
string.push('/');
string
})
};
result.pop(); // remove extra '/'
// replace with the root of the scheme if it's empty
Some(if result.is_empty() {
let pos = canon.find(':').map_or(canon.len(), |p| p + 1);
canon.truncate(pos);
canon
} else {
result
})
}
// XXX: chdir is not marked thread-safe (MT-safe) by POSIX. But on Linux it is simply run as a
// syscall and is therefore atomic, which is presumably why Rust's libstd doesn't synchronize
// access to this.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment