X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;ds=sidebyside;f=registry.cpp;h=c794ed186a4509904d99ccf45b7033e3cf2b67c9;hb=e3b93d0c37ae200fa0375e4be6f435008050b385;hp=0cb552f2e1f05048f8be0644592b50e72d45ddec;hpb=c262633514e151f681f4d8234185e2212a959c27;p=nssm.git diff --git a/registry.cpp b/registry.cpp index 0cb552f..c794ed1 100644 --- a/registry.cpp +++ b/registry.cpp @@ -17,7 +17,7 @@ int create_messages() { } /* Get path of this program */ - TCHAR path[MAX_PATH]; + TCHAR path[PATH_LENGTH]; GetModuleFileName(0, path, _countof(path)); /* Try to register the module but don't worry so much on failure */ @@ -222,64 +222,6 @@ int set_environment(TCHAR *service_name, HKEY key, TCHAR *value, TCHAR **env, un return 0; } -/* Replace NULL with CRLF. Leave NULL NULL as the end marker. */ -int format_environment(TCHAR *env, unsigned long envlen, TCHAR **formatted, unsigned long *newlen) { - unsigned long i, j; - *newlen = envlen; - - if (! *newlen) { - *formatted = 0; - return 0; - } - - for (i = 0; i < envlen; i++) if (! env[i] && env[i + 1]) ++*newlen; - - *formatted = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *newlen * sizeof(TCHAR)); - if (! *formatted) { - *newlen = 0; - return 1; - } - - for (i = 0, j = 0; i < envlen; i++) { - (*formatted)[j] = env[i]; - if (! env[i]) { - if (env[i + 1]) { - (*formatted)[j] = _T('\r'); - (*formatted)[++j] = _T('\n'); - } - } - j++; - } - - return 0; -} - -/* Strip CR and replace LF with NULL. */ -int unformat_environment(TCHAR *env, unsigned long envlen, TCHAR **unformatted, unsigned long *newlen) { - unsigned long i, j; - *newlen = 0; - - if (! envlen) { - *unformatted = 0; - return 0; - } - - for (i = 0; i < envlen; i++) if (env[i] != _T('\r')) ++*newlen; - /* Must end with two NULLs. */ - *newlen += 2; - - *unformatted = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *newlen * sizeof(TCHAR)); - if (! *unformatted) return 1; - - for (i = 0, j = 0; i < envlen; i++) { - if (env[i] == _T('\r')) continue; - if (env[i] == _T('\n')) (*unformatted)[j] = _T('\0'); - else (*unformatted)[j] = env[i]; - j++; - } - - return 0; -} int get_string(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool expand, bool sanitise, bool must_exist) { TCHAR *buffer = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, datalen); @@ -609,7 +551,7 @@ int get_parameters(nssm_service_t *service, STARTUPINFO *si) { if (get_number(key, NSSM_REG_ROTATE_BYTES_HIGH, &service->rotate_bytes_high, false) != 1) service->rotate_bytes_high = 0; /* Change to startup directory in case stdout/stderr are relative paths. */ - TCHAR cwd[MAX_PATH]; + TCHAR cwd[PATH_LENGTH]; GetCurrentDirectory(_countof(cwd), cwd); SetCurrentDirectory(service->dir);