diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-01-13 15:10:33 -0800 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-01-13 15:10:33 -0800 |
| commit | 07c39b1436f07b3a88daa39a3fc021c4bb3208e5 (patch) | |
| tree | 297cd77cafc71594ddc3ab97326a05d236b1a127 | |
| parent | 26334b64a29612be8190bedfbd507fa6ac6f8eb5 (diff) | |
| parent | 6441d619ba8984f469ecbd5e46358e982366b678 (diff) | |
| download | rust-07c39b1436f07b3a88daa39a3fc021c4bb3208e5.tar.gz rust-07c39b1436f07b3a88daa39a3fc021c4bb3208e5.zip | |
Merge pull request #4474 from tychosci/readlink_safe
core: Use libc::readlink function properly
| -rw-r--r-- | src/libcore/os.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 6ceb71d25ae..f602b230f45 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -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) } } } |
