| 23 | using std::string; |
| 24 | |
| 25 | string getEnvVar(const std::string &key) |
| 26 | { |
| 27 | #if defined(OS_WIN) |
| 28 | DWORD bufSize = 32767; // limit according to GetEnvironment Variable documentation |
| 29 | string retVal; |
| 30 | retVal.resize(bufSize); |
| 31 | bufSize = GetEnvironmentVariable(key.c_str(), &retVal[0], bufSize); |
| 32 | if (!bufSize) { |
| 33 | return string(""); |
| 34 | } else { |
| 35 | retVal.resize(bufSize); |
| 36 | return retVal; |
| 37 | } |
| 38 | #else |
| 39 | char * str = getenv(key.c_str()); |
| 40 | return str==NULL ? string("") : string(str); |
| 41 | #endif |
| 42 | } |
| 43 | |
| 44 | } |
| 45 | } |