Rollup merge of #56525 - udoprog:linux-current-exe, r=alexcrichton
Avoid extra copy and syscall in std::env::current_exe
This commit is contained in:
commit
bd8dd11d4d
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user