Skip to content

Commit

Permalink
Rollup merge of rust-lang#56525 - udoprog:linux-current-exe, r=alexcr…
Browse files Browse the repository at this point in the history
…ichton

Avoid extra copy and syscall in std::env::current_exe
  • Loading branch information
pietroalbini committed Dec 6, 2018
2 parents e941e1a + 3512fb0 commit bd8dd11
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,14 @@ pub fn current_exe() -> io::Result<PathBuf> {

#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
pub fn current_exe() -> io::Result<PathBuf> {
let selfexe = PathBuf::from("/proc/self/exe");
if selfexe.exists() {
::fs::read_link(selfexe)
} else {
Err(io::Error::new(io::ErrorKind::Other, "no /proc/self/exe available. Is /proc mounted?"))
match ::fs::read_link("/proc/self/exe") {
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
Err(io::Error::new(
io::ErrorKind::Other,
"no /proc/self/exe available. Is /proc mounted?"
))
},
other => other,
}
}

Expand Down

0 comments on commit bd8dd11

Please sign in to comment.