Merge pull request #4474 from tychosci/readlink_safe
core: Use libc::readlink function properly
This commit is contained in:
commit
07c39b1436
1 changed files with 11 additions and 2 deletions
|
@ -452,10 +452,19 @@ pub fn self_exe_path() -> Option<Path> {
|
|||
fn load_self() -> Option<~str> {
|
||||
unsafe {
|
||||
use libc::funcs::posix01::unistd::readlink;
|
||||
do fill_charp_buf() |buf, sz| {
|
||||
|
||||
let mut path_str = str::with_capacity(tmpbuf_sz);
|
||||
let len = do str::as_c_str(path_str) |buf| {
|
||||
let buf = buf as *mut c_char;
|
||||
do as_c_charp("/proc/self/exe") |proc_self_buf| {
|
||||
readlink(proc_self_buf, buf, sz) != (-1 as ssize_t)
|
||||
readlink(proc_self_buf, buf, tmpbuf_sz as size_t)
|
||||
}
|
||||
};
|
||||
if len == -1 {
|
||||
None
|
||||
} else {
|
||||
str::raw::set_len(&mut path_str, len as uint);
|
||||
Some(path_str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue