diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2024-12-23 12:14:46 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2024-12-25 21:48:03 +0100 |
commit | 3b8b519380651738a9d725353535d8141e7fa7ce (patch) | |
tree | b248f001c1acbe04137efe6b89b06f73467722b5 /test/testprog.cc | |
parent | 78c5477b3989d67169de2d05665adfb801caab23 (diff) |
WIP
Diffstat (limited to 'test/testprog.cc')
-rw-r--r-- | test/testprog.cc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/test/testprog.cc b/test/testprog.cc index dbfb665..c135061 100644 --- a/test/testprog.cc +++ b/test/testprog.cc @@ -2,7 +2,13 @@ #include <fstream> #include <string> -extern const char **environ; // see 'man environ' +#if defined(_WIN32) +#define WINDOWS_LEAN_AND_MEAN +#include <windows.h> +#undef max +#else +extern char **environ; // see 'man environ' +#endif int main(int argc, const char* argv[]) { @@ -20,10 +26,35 @@ int main(int argc, const char* argv[]) return 0; } std::ofstream ostrm(argv[2], std::ios::binary); +#if defined(_WIN32) + auto env_strings = GetEnvironmentStrings(); + const char* ptr = env_strings; + std::string env; + while(true) + { + if(*ptr == '\0') + { + if(env.empty()) + { + // no more + break; + } + ostrm << env << "\n"; + env.clear(); + ++ptr; + continue; + } + + env += *ptr; + ++ptr; + } + FreeEnvironmentStrings(env_strings); +#else for(auto current = environ; *current; ++current) { ostrm << (*current) << "\n"; } +#endif } if(cmd == "retval") |