From c5a5c4a03b6fab1518b8548d95e1d3050e251244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Wed, 13 Dec 2023 19:00:41 +0100 Subject: [PATCH] [SETUPAPI] Slightly improve pSetupGetFileTitle - Make the function return a pointer to const string. - Skip any drive path if any, looking for ':' just once. --- dll/win32/setupapi/misc.c | 34 +++++++++++++--------------- sdk/include/reactos/setupapi_undoc.h | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/dll/win32/setupapi/misc.c b/dll/win32/setupapi/misc.c index 7255269f9c4..d69cf387f94 100644 --- a/dll/win32/setupapi/misc.c +++ b/dll/win32/setupapi/misc.c @@ -986,34 +986,32 @@ DWORD WINAPI GetSetFileTimestamp(LPCWSTR lpFileName, /************************************************************************** * pSetupGetFileTitle [SETUPAPI.@] * - * Returns a pointer to the last part of a fully qualified file name. + * Returns a pointer to the last part (file name) of a full file path. * * PARAMS - * lpFileName [I] File name + * pFilePath [I] The fully qualified file path. * * RETURNS - * Pointer to a files name. + * Pointer to the file name, if any, or the terminating NULL. */ -LPWSTR WINAPI -pSetupGetFileTitle(LPCWSTR lpFileName) +PCWSTR WINAPI +pSetupGetFileTitle(PCWSTR pFilePath) { - LPWSTR ptr; - LPWSTR ret; + PCWSTR ptr, ret; WCHAR c; - TRACE("%s\n", debugstr_w(lpFileName)); + TRACE("%s\n", debugstr_w(pFilePath)); - ptr = (LPWSTR)lpFileName; - ret = ptr; - while (TRUE) + /* Skip the drive letter if any */ + ptr = pFilePath; + if (*ptr && ptr[1] == L':') + ptr += 2; + + /* Find the last path separator preceding the file name */ + for (ret = ptr; (c = *ptr);) { - c = *ptr; - - if (c == 0) - break; - - ptr++; - if (c == (WCHAR)'\\' || c == (WCHAR)'/' || c == (WCHAR)':') + ++ptr; + if (c == L'\\' || c == L'/') ret = ptr; } diff --git a/sdk/include/reactos/setupapi_undoc.h b/sdk/include/reactos/setupapi_undoc.h index 2dc74e16987..44b8cd43c14 100644 --- a/sdk/include/reactos/setupapi_undoc.h +++ b/sdk/include/reactos/setupapi_undoc.h @@ -65,7 +65,7 @@ WINSETUPAPI VOID WINAPI pSetupCenterWindowRelativeToParent(HWND); WINSETUPAPI BOOL WINAPI pSetupConcatenatePaths(LPWSTR, LPCWSTR, DWORD, LPDWORD); WINSETUPAPI PWSTR WINAPI pSetupDuplicateString(PCWSTR); WINSETUPAPI BOOL WINAPI pSetupEnablePrivilege(PCWSTR, BOOL); -WINSETUPAPI PWSTR WINAPI pSetupGetFileTitle(PCWSTR); +WINSETUPAPI PCWSTR WINAPI pSetupGetFileTitle(PCWSTR); WINSETUPAPI BOOL WINAPI pSetupGetVersionInfoFromImage(LPWSTR, PULARGE_INTEGER, LPWORD); WINSETUPAPI DWORD WINAPI pSetupGuidFromString(PCWSTR, LPGUID); WINSETUPAPI BOOL WINAPI pSetupIsGuidNull(LPGUID);