aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/posix.getenv.cc
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-29 19:19:23 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-29 19:19:23 +0100
commita8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df (patch)
tree6dafcf2674780649dcdc2649855722357837a68e /nihil.posix/posix.getenv.cc
parent4fa6821e0645ff61a9380cd090abff472205c630 (diff)
downloadnihil-a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df.tar.gz
nihil-a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df.tar.bz2
wip macOS port
Diffstat (limited to 'nihil.posix/posix.getenv.cc')
-rw-r--r--nihil.posix/posix.getenv.cc45
1 files changed, 0 insertions, 45 deletions
diff --git a/nihil.posix/posix.getenv.cc b/nihil.posix/posix.getenv.cc
deleted file mode 100644
index 36df950..0000000
--- a/nihil.posix/posix.getenv.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-
-/*
- * This source code is released into the public domain.
- */
-
-module;
-
-#include <cstdint>
-#include <expected>
-#include <string>
-#include <system_error>
-#include <vector>
-
-#include <unistd.h>
-
-module nihil.posix;
-
-import nihil.error;
-
-namespace nihil {
-
-auto getenv(std::string_view varname) -> std::expected<std::string, error>
-{
- // Start with a buffer of this size, and double it every iteration.
- constexpr auto bufinc = std::size_t{1024};
-
- auto cvarname = std::string(varname);
- auto buf = std::vector<char>(bufinc);
- for (;;) {
- auto const ret = ::getenv_r(cvarname.c_str(),
- buf.data(), buf.size());
-
- if (ret == 0)
- return {std::string(buf.data())};
-
- if (ret == -1 && errno == ERANGE) {
- buf.resize(buf.size() * 2);
- continue;
- }
-
- return std::unexpected(error(std::errc(errno)));
- }
-}
-
-} // namespace nihil