Skip to content

Commit 7021f15

Browse files
committed
Rollup merge of #56525 - udoprog:linux-current-exe, r=alexcrichton
Avoid extra copy and syscall in std::env::current_exe
2 parents 096c434 + 3512fb0 commit 7021f15

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Diff for: src/libstd/sys/unix/os.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,14 @@ pub fn current_exe() -> io::Result<PathBuf> {
283283

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

0 commit comments

Comments
 (0)