szaszm commented on code in PR #1895:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1895#discussion_r1983052605


##########
utils/src/utils/Environment.cpp:
##########
@@ -123,4 +130,47 @@ bool Environment::isRunningAsService() {
   return runningAsService;
 }
 
+std::unordered_map<std::string, std::string> 
Environment::getEnvironmentVariables() {
+  std::unordered_map<std::string, std::string> env_var_map;
+
+  Environment::accessEnvironment([&env_var_map](){
+#ifdef WIN32
+    LPWCH env_strings = GetEnvironmentStringsW();
+    if (!env_strings) {
+      return;
+    }
+
+    LPWCH env = env_strings;
+
+    while (*env) {
+      std::wstring wstring_variable_key_value_pair(env);
+
+      int size_needed = WideCharToMultiByte(CP_UTF8, 0, 
wstring_variable_key_value_pair.c_str(), -1, nullptr, 0, nullptr, nullptr);
+      std::vector<char> buffer(size_needed);
+      WideCharToMultiByte(CP_UTF8, 0, wstring_variable_key_value_pair.c_str(), 
-1, buffer.data(), size_needed, nullptr, nullptr);
+
+      std::string variable_key_value_pair(buffer.data(), size_needed - 1);

Review Comment:
   There is `to_string` in UnicodeConversion.h that may do the trick with 
simpler code.



##########
utils/src/utils/Environment.cpp:
##########
@@ -123,4 +130,47 @@ bool Environment::isRunningAsService() {
   return runningAsService;
 }
 
+std::unordered_map<std::string, std::string> 
Environment::getEnvironmentVariables() {
+  std::unordered_map<std::string, std::string> env_var_map;
+
+  Environment::accessEnvironment([&env_var_map](){
+#ifdef WIN32
+    LPWCH env_strings = GetEnvironmentStringsW();

Review Comment:
   The Windows version seems thread-safe to me, I think only the UNIX API is 
broken in this archaic way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to