+
+/*
+ Duplicate an environment block returned by GetEnvironmentStrings().
+ Since such a block is by definition readonly, and duplicate_environment()
+ modifies its inputs, this function takes a copy of the input and operates
+ on that.
+*/
+void duplicate_environment_strings(TCHAR *env) {
+ TCHAR *newenv = copy_environment_block(env);
+ if (! newenv) return;
+
+ duplicate_environment(newenv);
+ HeapFree(GetProcessHeap(), 0, newenv);
+}
+
+/* Safely get a copy of the current environment. */
+TCHAR *copy_environment() {
+ TCHAR *rawenv = GetEnvironmentStrings();
+ if (! rawenv) return NULL;
+ TCHAR *env = copy_environment_block(rawenv);
+ FreeEnvironmentStrings(rawenv);
+ return env;
+}