From 481f9ba1aee62fea092184f2243d210a8686781f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 14 Jun 2018 18:13:04 +0200 Subject: Add portable environment variable manipulation functions --- libbutl/utility.ixx | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libbutl/utility.ixx') diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx index d4aaa65..565a694 100644 --- a/libbutl/utility.ixx +++ b/libbutl/utility.ixx @@ -2,6 +2,10 @@ // copyright : Copyright (c) 2014-2018 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file +#ifndef __cpp_lib_modules +#include // getenv() +#endif + namespace butl { inline char @@ -199,4 +203,13 @@ namespace butl throw std::istream::failure (""); } + + inline optional + getenv (const std::string& name) + { + if (const char* r = std::getenv (name.c_str ())) + return std::string (r); + + return nullopt; + } } -- cgit v1.1