Changeset 19784
- Timestamp:
- 01/30/07 10:30:48 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/vapor/vpr/md/NSPR/SystemNSPR.cpp
r19729 r19784 38 38 #ifdef VPR_OS_Windows 39 39 # include <winsock2.h> /* For struct tiemval */ 40 # include <cstdlib> /* For std::getenv() and _putenv() */ 41 #else 42 # include <cstring> /* For strdup() */ 40 43 #endif 41 44 45 #include <sstream> 42 46 #include <boost/concept_check.hpp> 43 47 … … 59 63 } 60 64 65 bool SystemNSPR::getenv(const std::string& name, std::string& result) 66 { 67 bool status(false); 68 69 #if defined(VPR_OS_Windows) 70 #if defined(_MSC_VER) && _MSC_VER >= 1400 71 char* val(NULL); 72 size_t num; 73 _dupenv_s(&val, &num, name.c_str()); 74 #else 75 const char* val = std::getenv(name.c_str()); 76 #endif 77 #else 78 const char* val = PR_GetEnv(name.c_str()); 79 #endif 80 81 if ( val != NULL ) 82 { 83 result = val; 84 status = true; 85 86 #if defined(VPR_OS_Windows) && defined(_MSC_VER) && _MSC_VER >= 1400 87 std::free(val); 88 val = NULL; 89 #endif 90 } 91 92 return status; 61 93 } 94 95 bool SystemNSPR::setenv(const std::string& name, const std::string& value) 96 { 97 bool status(false); 98 // NSPR and _putenv() require the form "name=value". 99 std::ostringstream env_stream; 100 env_stream << name << "=" << value; 101 102 #if defined(VPR_OS_Windows) 103 const int ret_val = _putenv(env_stream.str().c_str()); 104 status = ret_val == 0; 105 #else 106 // NSPR takes possesion of the string memory. 107 const PRStatus ret_val = PR_SetEnv(strdup(env_stream.str().c_str())); 108 status = ret_val == PR_SUCCESS; 109 #endif 110 111 return status; 112 } 113 114 } juggler/trunk/modules/vapor/vpr/md/NSPR/SystemNSPR.h
r19729 r19784 209 209 * variable could not be found in the run-time environment. 210 210 */ 211 static bool getenv(const std::string& name, std::string& result) 212 { 213 char* val; 214 bool status(false); 215 216 val = PR_GetEnv(name.c_str()); 217 218 if ( val != NULL ) 219 { 220 result = val; 221 status = true; 222 } 223 224 return status; 225 } 211 static bool getenv(const std::string& name, std::string& result); 226 212 227 213 /** … … 242 228 * variable set operation failed. 243 229 */ 244 static bool setenv(const std::string& name, const std::string& value) 245 { 246 // NSPR requires form of "name=value" 247 // NSPR takes possesion of the string memory, so we just leak here 248 std::string* set_value = new std::string(name); 249 (*set_value) += "="; 250 (*set_value) += value; 251 252 const PRStatus ret_val = PR_SetEnv(set_value->c_str()); 253 254 return ret_val == PR_SUCCESS; 255 } 230 static bool setenv(const std::string& name, const std::string& value); 256 231 257 232 /**
