X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fwindows%2Fenviron.cpp;fp=source%2Fcore%2Fwindows%2Fenviron.cpp;h=ff5c2b001dcb2691fb09871b1afc129882589a1b;hp=0000000000000000000000000000000000000000;hb=f804a61c1c58529e7c98555a921b56bc05059d5e;hpb=31cc8f0c6e874e2417e76eda50af34fd17bcd90c diff --git a/source/core/windows/environ.cpp b/source/core/windows/environ.cpp new file mode 100644 index 0000000..ff5c2b0 --- /dev/null +++ b/source/core/windows/environ.cpp @@ -0,0 +1,42 @@ +#include +#include "environ.h" +#include "mutex.h" + +#ifdef __GNUC__ +extern "C" errno_t getenv_s(size_t *, char *, size_t, const char *); +#endif + +using namespace std; + +namespace Msp { + +static Mutex &env_mutex() +{ + static Mutex mutex; + return mutex; +} + +string getenv(const string &name) +{ + MutexLock _lock(env_mutex()); + char buffer[1024]; + size_t result; + if(!getenv_s(&result, buffer, sizeof(buffer), name.c_str())) + return buffer; + else + return string(); +} + +void setenv(const string &name, const string &value) +{ + MutexLock _lock(env_mutex()); + _putenv_s(name.c_str(), value.c_str()); +} + +void unsetenv(const string &name) +{ + MutexLock _lock(env_mutex()); + _putenv_s(name.c_str(), ""); +} + +}