]> git.tdb.fi Git - libs/core.git/blob - source/core/unix/environ.cpp
Add wrappers for environment manipulation functions
[libs/core.git] / source / core / unix / environ.cpp
1 #include <cstdlib>
2 #include "environ.h"
3 #include "mutex.h"
4
5 using namespace std;
6
7 namespace Msp {
8
9 static Mutex &env_mutex()
10 {
11         static Mutex mutex;
12         return mutex;
13 }
14
15 string getenv(const string &name)
16 {
17         MutexLock _lock(env_mutex());
18         const char *value = std::getenv(name.c_str());
19         return (value ? string(value) : string());
20 }
21
22 void setenv(const string &name, const string &value)
23 {
24         MutexLock _lock(env_mutex());
25         ::setenv(name.c_str(), value.c_str(), true);
26 }
27
28 void unsetenv(const string &name)
29 {
30         MutexLock _lock(env_mutex());
31         ::unsetenv(name.c_str());
32 }
33
34 }