diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-02-01 20:37:32 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-02-21 21:42:02 +0100 |
commit | 5809172695f0b174ae036dc829e6d3176d926342 (patch) | |
tree | ad8961645c716da67b913b425cc72534a5d49297 /test/testprog.cc | |
parent | 8a40f5f49d428bbc89f54144d893a9fa16e3156c (diff) |
WIPmsvc
Diffstat (limited to 'test/testprog.cc')
-rw-r--r-- | test/testprog.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/testprog.cc b/test/testprog.cc index 93edc3f..18c2c74 100644 --- a/test/testprog.cc +++ b/test/testprog.cc @@ -5,6 +5,14 @@ extern char **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[]) { if(argc < 2) @@ -20,11 +28,41 @@ int main(int argc, const char* argv[]) { return 0; } + std::ofstream ostrm(argv[2], std::ios::binary); + if(ostrm.bad()) + { + std::cout << "Error: Could not write to " << argv[2] << "\n"; + } +#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") |