]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/unix/environ.cpp
Add wrappers for environment manipulation functions
[libs/core.git] / source / core / unix / environ.cpp
diff --git a/source/core/unix/environ.cpp b/source/core/unix/environ.cpp
new file mode 100644 (file)
index 0000000..037a0e9
--- /dev/null
@@ -0,0 +1,34 @@
+#include <cstdlib>
+#include "environ.h"
+#include "mutex.h"
+
+using namespace std;
+
+namespace Msp {
+
+static Mutex &env_mutex()
+{
+       static Mutex mutex;
+       return mutex;
+}
+
+string getenv(const string &name)
+{
+       MutexLock _lock(env_mutex());
+       const char *value = std::getenv(name.c_str());
+       return (value ? string(value) : string());
+}
+
+void setenv(const string &name, const string &value)
+{
+       MutexLock _lock(env_mutex());
+       ::setenv(name.c_str(), value.c_str(), true);
+}
+
+void unsetenv(const string &name)
+{
+       MutexLock _lock(env_mutex());
+       ::unsetenv(name.c_str());
+}
+
+}