Avoid extra copy and syscall in std::env::current_exe
This commit is contained in:
parent
af7554d3a2
commit
3512fb0467
1 changed files with 8 additions and 5 deletions
|
@ -283,11 +283,14 @@ pub fn current_exe() -> io::Result<PathBuf> {
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
|
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
|
||||||
pub fn current_exe() -> io::Result<PathBuf> {
|
pub fn current_exe() -> io::Result<PathBuf> {
|
||||||
let selfexe = PathBuf::from("/proc/self/exe");
|
match ::fs::read_link("/proc/self/exe") {
|
||||||
if selfexe.exists() {
|
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
|
||||||
::fs::read_link(selfexe)
|
Err(io::Error::new(
|
||||||
} else {
|
io::ErrorKind::Other,
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "no /proc/self/exe available. Is /proc mounted?"))
|
"no /proc/self/exe available. Is /proc mounted?"
|
||||||
|
))
|
||||||
|
},
|
||||||
|
other => other,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue