Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement realpath() #28

Merged
merged 3 commits into from Jun 20, 2017
Merged

Implement realpath() #28

merged 3 commits into from Jun 20, 2017

Conversation

@ids1024
Copy link
Member

@ids1024 ids1024 commented Jun 20, 2017

No description provided.


libc_fn!(unsafe realpath(path: *const c_char, resolved_path: *mut c_char) -> Result<*mut c_char> {
let fd = syscall::open(::cstr_to_slice(path), O_STAT)?;
let buf = slice::from_raw_parts_mut(resolved_path as *mut u8, 4095);

This comment has been minimized.

@jackpot51

jackpot51 Jun 20, 2017
Member

How do you know resolved_path will be 4096 bytes long? Shouldn't it be PATH_MAX ?

This comment has been minimized.

@jackpot51

jackpot51 Jun 20, 2017
Member

Also,

       If resolved_path is specified as NULL, then realpath() uses malloc(3)
       to allocate a buffer of up to PATH_MAX bytes to hold the resolved
       pathname, and returns a pointer to this buffer.  The caller should
       deallocate this buffer using free(3).

This comment has been minimized.

@ids1024

ids1024 Jun 20, 2017
Author Member

Newlib appears to define PATH_MAX to 4096 by default; I suppose that should be defined as a constant in the Rust code to be clearer. Good point about accepting NULL; I'll add that.

ids1024 added 2 commits Jun 20, 2017
@ids1024
Copy link
Member Author

@ids1024 ids1024 commented Jun 20, 2017

Okay; I've fixed it now.

@jackpot51 jackpot51 merged commit e960bcf into redox-os:redox Jun 20, 2017
@ids1024 ids1024 deleted the ids1024:realpath branch Aug 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants