Implement realpath

This commit is contained in:
jD91mZM2
2018-10-07 10:32:36 +02:00
parent 26d629674a
commit 418a960f3b
11 changed files with 120 additions and 11 deletions
+8
View File
@@ -0,0 +1,8 @@
sys_includes = []
include_guard = "_LIMITS_H"
language = "C"
style = "Tag"
trailer = "#include <bits/limits.h>"
[enum]
prefix_with_name = true
+3
View File
@@ -0,0 +1,3 @@
//! limits.h implementation for relibc
pub const PATH_MAX: usize = 4096;
+1
View File
@@ -10,6 +10,7 @@ pub mod fnmatch;
pub mod getopt;
pub mod grp;
pub mod inttypes;
pub mod limits;
pub mod locale;
pub mod netdb;
pub mod netinet_in;
+20 -4
View File
@@ -1,6 +1,6 @@
//! stdlib implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/stdlib.h.html
use core::{intrinsics, iter, mem, ptr};
use core::{intrinsics, iter, mem, ptr, slice};
use rand::distributions::Alphanumeric;
use rand::prng::XorShiftRng;
use rand::rngs::JitterRng;
@@ -12,6 +12,7 @@ use header::fcntl::*;
use header::string::*;
use header::time::constants::CLOCK_MONOTONIC;
use header::time::timespec;
use header::limits;
use header::wchar::*;
use header::{ctype, errno, unistd};
use platform;
@@ -572,9 +573,24 @@ pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void
platform::realloc(ptr, size)
}
// #[no_mangle]
pub extern "C" fn realpath(file_name: *const c_char, resolved_name: *mut c_char) -> *mut c_char {
unimplemented!();
#[no_mangle]
pub unsafe extern "C" fn realpath(pathname: *const c_char, resolved: *mut c_char) -> *mut c_char {
let mut path = [0; limits::PATH_MAX];
{
let slice = if resolved.is_null() {
&mut path
} else {
slice::from_raw_parts_mut(resolved as *mut u8, 4096)
};
if Sys::realpath(CStr::from_ptr(pathname), slice) < 0 {
return ptr::null_mut();
}
}
if !resolved.is_null() {
resolved
} else {
strdup(path.as_ptr() as *const i8)
}
}
// #[no_mangle]
+3 -5
View File
@@ -3,7 +3,7 @@
use core::{ptr, slice};
use c_str::CStr;
use header::sys_time;
use header::{limits, sys_time};
use header::time::timespec;
use platform;
use platform::types::*;
@@ -35,8 +35,6 @@ pub const STDIN_FILENO: c_int = 0;
pub const STDOUT_FILENO: c_int = 1;
pub const STDERR_FILENO: c_int = 2;
const PATH_MAX: usize = 4096;
#[no_mangle]
pub extern "C" fn _exit(status: c_int) {
Sys::exit(status)
@@ -190,7 +188,7 @@ pub extern "C" fn ftruncate(fildes: c_int, length: off_t) -> c_int {
#[no_mangle]
pub extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char {
let alloc = buf.is_null();
let mut stack_buf = [0; PATH_MAX];
let mut stack_buf = [0; limits::PATH_MAX];
if alloc {
buf = stack_buf.as_mut_ptr();
size = stack_buf.len();
@@ -305,7 +303,7 @@ pub extern "C" fn getuid() -> uid_t {
#[no_mangle]
pub extern "C" fn getwd(path_name: *mut c_char) -> *mut c_char {
getcwd(path_name, PATH_MAX)
getcwd(path_name, limits::PATH_MAX)
}
#[no_mangle]