1
Fork 0

Avoid extra copy and syscall in std::env::current_exe

This commit is contained in:
John-John Tedro 2018-12-05 02:48:18 +01:00
parent af7554d3a2
commit 3512fb0467

View file

@ -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,
} }
} }