diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2024-12-23 12:14:46 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-01-08 19:01:09 +0100 |
commit | a7f2893bfb5149944be598bd93b642ead27c1886 (patch) | |
tree | b2086fda57e5453b3493d91923d1855bc2bcd0b5 /test/testprog.cc | |
parent | c50b7554cfd23b53107f2a2917a0be22a68b0c11 (diff) |
WIPmsvc-rebased
Diffstat (limited to 'test/testprog.cc')
-rw-r--r-- | test/testprog.cc | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/test/testprog.cc b/test/testprog.cc index dbfb665..58a31ac 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[]) { @@ -19,11 +25,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") |