X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=env.cpp;h=a1ca9004e29274ed5e4ed4d16df7f121259de724;hb=d47dca0afe81c1c8e75c518da5a51829e61ad1cd;hp=063b60f16b4b62174f4b280f4e42fadb81ec38b2;hpb=620fc9f56975c9319a1b0e0be556e264ad1d485d;p=nssm.git diff --git a/env.cpp b/env.cpp index 063b60f..a1ca900 100644 --- a/env.cpp +++ b/env.cpp @@ -86,7 +86,7 @@ static int set_environment_block(TCHAR *env, bool set) { else { if (! SetEnvironmentVariable(s, NULL)) ret++; } - for (t++ ; *t; t++); + for (t++; *t; t++); } s = t; } @@ -129,8 +129,7 @@ int duplicate_environment(TCHAR *rawenv) { -1 on error. */ int test_environment(TCHAR *env) { - TCHAR path[PATH_LENGTH]; - GetModuleFileName(0, path, _countof(path)); + TCHAR *path = (TCHAR *) nssm_imagepath(); STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); @@ -171,3 +170,12 @@ void duplicate_environment_strings(TCHAR *env) { 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; +}