diff options
| author | John-John Tedro <udoprog@tedro.se> | 2018-12-05 02:48:18 +0100 |
|---|---|---|
| committer | John-John Tedro <udoprog@tedro.se> | 2018-12-05 02:55:12 +0100 |
| commit | 3512fb046799fe02555b12d1e180d0ef83aba849 (patch) | |
| tree | c00cf6fc5f7ea05be1a324fb82e93c4ec03f2f34 /src/libstd/sys | |
| parent | af7554d3a2e9e6171ca44bd1d4828606a9868f74 (diff) | |
| download | rust-3512fb046799fe02555b12d1e180d0ef83aba849.tar.gz rust-3512fb046799fe02555b12d1e180d0ef83aba849.zip | |
Avoid extra copy and syscall in std::env::current_exe
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index b387a8d59a5..03e81a720dc 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -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, } } |
