From a86b1cccb1b71d30ff9893b932b644b324ebb878 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 12 Apr 2020 22:43:00 +0200 Subject: [PATCH] Small optimization. --- setup-launcher.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/setup-launcher.c b/setup-launcher.c index 69285e6..fbba1b2 100644 --- a/setup-launcher.c +++ b/setup-launcher.c @@ -60,17 +60,6 @@ static wchar_t *copy(wchar_t *const buffer, const wchar_t *const str, const size return buffer; } -static wchar_t *append(wchar_t *const buffer, const wchar_t *const str, const size_t buff_size) -{ - const size_t current_len = wcslen(buffer); - if(current_len < buff_size) - { - wcsncat(buffer, str, buff_size - current_len); - buffer[buff_size - 1U] = L'\0'; - } - return buffer; -} - static wchar_t *append_swprintf(wchar_t *const buffer, const size_t buff_size, const wchar_t *const format, ...) { const size_t current_len = wcslen(buffer); @@ -165,7 +154,7 @@ static void get_absolute_path(const wchar_t *const path, wchar_t *const full_pat } } -static void remove_file_name(wchar_t *const path) +static wchar_t *remove_file_name(wchar_t *const path) { const size_t pos_sep = _max_pos(last_index(path, L'/'), last_index(path, L'\\')); if(pos_sep != SIZE_MAX) @@ -179,9 +168,10 @@ static void remove_file_name(wchar_t *const path) path[pos_sep] = L'\0'; } } + return path; } -static void remove_file_extension(wchar_t *const path) +static wchar_t *remove_file_extension(wchar_t *const path) { const size_t pos_sep = _max_pos(last_index(path, L'/'), last_index(path, L'\\')); const size_t pos_dot = last_index(path, L'.'); @@ -189,6 +179,7 @@ static void remove_file_extension(wchar_t *const path) { path[pos_dot] = L'\0'; } + return path; } static wchar_t *path_append(wchar_t *const base_path, const wchar_t *const extension, const size_t buff_size) @@ -601,9 +592,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, path_append(rundll32_path, L"rundll32.exe", MAX_PATHLEN); /*get path of launcher DLL*/ - copy(library_path, executable_path, MAX_PATHLEN); - remove_file_extension(library_path); - append(library_path, L".dll", MAX_PATHLEN); + swprintf(library_path, MAX_PATHLEN, L"%s.dll", remove_file_extension(executable_path)); /*mangles executable_path!*/ /*make sure the launcher DLL exists*/ if(!file_exists(library_path)) @@ -615,10 +604,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, /*build parameter string for RunDLL*/ swprintf(parameters, MAX_CMDNLEN, contains_space(library_path) ? L"\"%s\",startup" : L"%s,startup", library_path); - append_swprintf(parameters, MAX_CMDNLEN, contains_space(setup_absolute_path) ? L" \"%s\"" : L" %s", setup_absolute_path); + append_swprintf(parameters, MAX_CMDNLEN, contains_space(setup_absolute_path) ? L"\x20\"%s\"" : L"\x20%s", setup_absolute_path); if(extra_args && (*extra_args)) { - append_swprintf(parameters, MAX_CMDNLEN, L" %s", extra_args); + append_swprintf(parameters, MAX_CMDNLEN, L"\x20%s", extra_args); } /*now actually call the launcher DLL*/ -- 2.11.4.GIT