diff options
| author | Aris Merchant <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-06-24 16:04:24 -0700 |
|---|---|---|
| committer | Aris Merchant <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-07-05 22:19:23 -0700 |
| commit | a12107afaaa634cd7352d3828caef89a975299bb (patch) | |
| tree | 0a36d26e1d64f16ceab64e9a926bdc22d371c619 /library/std/src/sys/windows | |
| parent | d26e01e9df416304f7d0cc425bd0290560e12fae (diff) | |
| download | rust-a12107afaaa634cd7352d3828caef89a975299bb.tar.gz rust-a12107afaaa634cd7352d3828caef89a975299bb.zip | |
Make `getenv` return an Option instead of a Result
Diffstat (limited to 'library/std/src/sys/windows')
| -rw-r--r-- | library/std/src/sys/windows/os.rs | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/library/std/src/sys/windows/os.rs b/library/std/src/sys/windows/os.rs index 77c378a66af..8db97ba50a8 100644 --- a/library/std/src/sys/windows/os.rs +++ b/library/std/src/sys/windows/os.rs @@ -253,22 +253,13 @@ pub fn chdir(p: &path::Path) -> io::Result<()> { cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(drop) } -pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { - let k = to_u16s(k)?; - let res = super::fill_utf16_buf( +pub fn getenv(k: &OsStr) -> Option<OsString> { + let k = to_u16s(k).ok()?; + super::fill_utf16_buf( |buf, sz| unsafe { c::GetEnvironmentVariableW(k.as_ptr(), buf, sz) }, |buf| OsStringExt::from_wide(buf), - ); - match res { - Ok(value) => Ok(Some(value)), - Err(e) => { - if e.raw_os_error() == Some(c::ERROR_ENVVAR_NOT_FOUND as i32) { - Ok(None) - } else { - Err(e) - } - } - } + ) + .ok() } pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { |
