diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2018-12-06 07:48:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-06 07:48:58 +0100 |
| commit | bd8dd11d4d907b67ce20952c3a9ebe769e4ae547 (patch) | |
| tree | 9a2907941f2bbe3df665333bca1b264bf12195fe | |
| parent | e941e1a62400f5f716aa28e06460d0bc0736d8c9 (diff) | |
| parent | 3512fb046799fe02555b12d1e180d0ef83aba849 (diff) | |
| download | rust-bd8dd11d4d907b67ce20952c3a9ebe769e4ae547.tar.gz rust-bd8dd11d4d907b67ce20952c3a9ebe769e4ae547.zip | |
Rollup merge of #56525 - udoprog:linux-current-exe, r=alexcrichton
Avoid extra copy and syscall in std::env::current_exe
| -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, } } |
