cae  0.0.0
Cross-API graphics engine
Loading...
Searching...
No Matches
env.cpp
Go to the documentation of this file.
1#include "Utils/Env.hpp"
2
3#ifdef _WIN32
4#include <windows.h>
5#endif
6
7#include <cstring>
8
9std::unordered_map<std::string, std::string> utl::getEnvMap(const char *const *env)
10{
11 std::unordered_map<std::string, std::string> cpyEnv;
12
13#ifdef _WIN32
14 const LPCH envStrings = GetEnvironmentStringsA();
15 if (envStrings == nullptr)
16 {
17 return cpyEnv;
18 }
19
20 for (LPCH var = envStrings; *var != 0; var += std::strlen(var) + 1)
21 {
22 std::string entry(var);
23 if (const auto pos = entry.find('='); pos != std::string::npos)
24 {
25 cpyEnv.emplace(entry.substr(0, pos), entry.substr(pos + 1));
26 }
27 }
28
29 FreeEnvironmentStringsA(envStrings);
30#else
31 for (const char *const *current = env; (current != nullptr) && (*current != nullptr); ++current)
32 {
33 std::string entry(*current);
34 if (const auto pos = entry.find('='); pos != std::string::npos)
35 {
36 cpyEnv.emplace(entry.substr(0, pos), entry.substr(pos + 1));
37 }
38 }
39#endif
40
41 return cpyEnv;
42}
This file contains env utility functions.
std::unordered_map< std::string, std::string > getEnvMap(const char *const *env)
Get environment variables as a map.
Definition env.cpp:9