8 #ifndef BOOST_NOWIDE_CENV_H_INCLUDED 9 #define BOOST_NOWIDE_CENV_H_INCLUDED 14 #include <boost/config.hpp> 15 #include <boost/nowide/stackstring.hpp> 19 #include <boost/nowide/windows.hpp> 24 #if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN) 30 inline char *
getenv(
char const *key)
40 if(!name.convert(key))
43 static const size_t buf_size = 64;
44 wchar_t buf[buf_size];
45 std::vector<wchar_t> tmp;
47 size_t n = GetEnvironmentVariableW(name.c_str(),buf,buf_size);
48 if(n == 0 && GetLastError() == 203)
51 tmp.resize(n+1,L
'\0');
52 n = GetEnvironmentVariableW(name.c_str(),&tmp[0],
static_cast<unsigned>(tmp.size() - 1));
54 if(n >= tmp.size() - 1)
58 if(!value.convert(ptr))
68 inline int setenv(
char const *key,
char const *value,
int override)
71 if(!name.convert(key))
75 if(!(GetEnvironmentVariableW(name.c_str(),unused,2)==0 && GetLastError() == 203))
79 if(!wval.convert(value))
81 if(SetEnvironmentVariableW(name.c_str(),wval.c_str()))
91 if(!name.convert(key))
93 if(SetEnvironmentVariableW(name.c_str(),0))
102 char const *key = string;
103 char const *key_end = string;
104 while(*key_end!=
'=' && key_end!=
'\0')
109 if(!wkey.convert(key,key_end))
113 if(!wvalue.convert(key_end+1))
116 if(SetEnvironmentVariableW(wkey.c_str(),wvalue.c_str()))
basic_stackstring< wchar_t, char, 16 > wshort_stackstring
Definition: stackstring.hpp:142
int setenv(char const *key, char const *value, int override)
UTF-8 aware setenv, key - the variable name, value is a new UTF-8 value,.
Definition: cenv.hpp:68
int putenv(char *string)
UTF-8 aware putenv implementation, expects string in format KEY=VALUE.
Definition: cenv.hpp:100
int unsetenv(char const *key)
Remove enviroment variable key.
Definition: cenv.hpp:88
char * getenv(char const *key)
UTF-8 aware getenv. Returns 0 if the variable is not set.
Definition: cenv.hpp:35
basic_stackstring< char, wchar_t, 256 > stackstring
Definition: stackstring.hpp:138
A class that allows to create a temporary wide or narrow UTF strings from wide or narrow UTF source...
Definition: stackstring.hpp:25