]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/windows/environ.cpp
Add wrappers for environment manipulation functions
[libs/core.git] / source / core / windows / environ.cpp
diff --git a/source/core/windows/environ.cpp b/source/core/windows/environ.cpp
new file mode 100644 (file)
index 0000000..ff5c2b0
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+#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(), "");
+}
+
+}