Make redox fpath only return new format

This commit is contained in:
Jeremy Soller
2024-02-12 15:09:13 -07:00
parent 8313fc1c77
commit 534e7ef80c
3 changed files with 34 additions and 5 deletions
Generated
+2 -2
View File
@@ -200,9 +200,9 @@ dependencies = [
[[package]]
name = "redox-path"
version = "0.1.1"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f45c7275fe1467ea17542c01766ae9872fa98aa7fe06ba5ea6595f7a9f0699c6"
checksum = "64072665120942deff5fd5425d6c1811b854f4939e7f1c01ce755f64432bbea7"
[[package]]
name = "redox_syscall"
+1 -1
View File
@@ -53,7 +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"
redox-path = "0.2"
[features]
default = ["check_against_libc_crate"]
+31 -2
View File
@@ -11,7 +11,7 @@ use crate::{
header::{
dirent::dirent,
errno::{EBADR, EINVAL, EIO, ENOENT, ENOMEM, ENOSYS, EPERM, ERANGE},
fcntl,
fcntl, limits,
sys_mman::{MAP_ANONYMOUS, MAP_FAILED, PROT_READ, PROT_WRITE},
sys_random,
sys_resource::{rlimit, RLIM_INFINITY},
@@ -822,7 +822,36 @@ impl Pal for Sys {
}
fn fpath(fildes: c_int, out: &mut [u8]) -> ssize_t {
e(syscall::fpath(fildes as usize, out)) as ssize_t
// Since this is used by realpath, it converts from the old format to the new one for
// compatibility reasons
let mut buf = [0; limits::PATH_MAX];
let count = match syscall::fpath(fildes as usize, &mut buf) {
Ok(ok) => ok,
Err(err) => return e(Err(err)) as ssize_t,
};
let redox_path = match str::from_utf8(&buf[..count])
.ok()
.and_then(|x| redox_path::RedoxPath::from_absolute(x))
{
Some(some) => some,
None => return e(Err(syscall::Error::new(EINVAL))) as ssize_t,
};
let (scheme, reference) = match redox_path.as_parts() {
Some(some) => some,
None => return e(Err(syscall::Error::new(EINVAL))) as ssize_t,
};
let mut cursor = io::Cursor::new(out);
let res = match scheme.as_ref() {
"file" => write!(cursor, "/{}", reference.as_ref()),
_ => write!(cursor, "/scheme/{}/{}", scheme.as_ref(), reference.as_ref()),
};
match res {
Ok(()) => cursor.position() as ssize_t,
Err(_err) => e(Err(syscall::Error::new(syscall::ENAMETOOLONG))) as ssize_t,
}
}
fn readlink(pathname: CStr, out: &mut [u8]) -> ssize_t {