diff options
Diffstat (limited to 'nihil.posix/getenv.cc')
| -rw-r--r-- | nihil.posix/getenv.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/nihil.posix/getenv.cc b/nihil.posix/getenv.cc index ad93305..c596902 100644 --- a/nihil.posix/getenv.cc +++ b/nihil.posix/getenv.cc @@ -44,10 +44,16 @@ auto getenv(std::string_view varname) -> std::expected<std::string, error> return std::unexpected(error(std::errc(errno))); } #else // NIHIL_HAVE_GETENV_R + errno = 0; auto *v = ::getenv(cvarname.c_str()); - if (v == nullptr) + + if (v != nullptr) + return {std::string(v)}; + + if (errno != 0) return std::unexpected(error(std::errc(errno))); - return {std::string(v)}; + + return std::unexpected(error(std::errc::no_such_file_or_directory)); #endif // NIHIL_HAVE_GETENV_R } |
