From c96f8afe3b3e453dcc6d4b8c9e0ae3b143e2188f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 23 Dec 2024 12:14:46 +0100 Subject: WIP --- test/testprog.cc | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'test/testprog.cc') 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 #include -extern const char **environ; // see 'man environ' +#if defined(_WIN32) +#define WINDOWS_LEAN_AND_MEAN +#include +#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") -- cgit v1.2.3