From: Robert Wilhelm Subject: [PATCH v4 1/2] scrrun: Extract code to new helper function build_path. Message-Id: Date: Sun, 28 Nov 2021 22:57:55 +0100 Signed-off-by: Robert Wilhelm --- Supersedes 220459. v4: Fix issues as pointed out by Nikolay: Leave EPOINTER check in original function and do not specify calling convention. --- dlls/scrrun/filesystem.c | 103 ++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c index 68ef1786af9..359d86bb8fd 100644 --- a/dlls/scrrun/filesystem.c +++ b/dlls/scrrun/filesystem.c @@ -223,6 +223,59 @@ static BSTR get_full_path(BSTR path, const WIN32_FIND_DATAW *data) return SysAllocString(buffW); } +static HRESULT build_path( BSTR Path, BSTR Name, BSTR *Result) +{ + BSTR ret; + + if (Path && Name) + { + int path_len = SysStringLen(Path), name_len = SysStringLen(Name); + + /* if both parts have backslashes strip one from Path */ + if (Path[path_len-1] == '\\' && Name[0] == '\\') + { + path_len -= 1; + + ret = SysAllocStringLen(NULL, path_len + name_len); + if (ret) + { + lstrcpyW(ret, Path); + ret[path_len] = 0; + lstrcatW(ret, Name); + } + } + else if (Path[path_len-1] != '\\' && Name[0] != '\\') + { + ret = SysAllocStringLen(NULL, path_len + name_len + 1); + if (ret) + { + lstrcpyW(ret, Path); + if (Path[path_len-1] != ':') + wcscat(ret, L"\\"); + lstrcatW(ret, Name); + } + } + else + { + ret = SysAllocStringLen(NULL, path_len + name_len); + if (ret) + { + lstrcpyW(ret, Path); + lstrcatW(ret, Name); + } + } + } + else if (Path || Name) + ret = SysAllocString(Path ? Path : Name); + else + ret = SysAllocStringLen(NULL, 0); + + if (!ret) return E_OUTOFMEMORY; + *Result = ret; + + return S_OK; +} + static BOOL textstream_check_iomode(struct textstream *This, enum iotype type) { if (type == IORead) @@ -3034,59 +3087,11 @@ static HRESULT WINAPI filesys_get_Drives(IFileSystem3 *iface, IDriveCollection * static HRESULT WINAPI filesys_BuildPath(IFileSystem3 *iface, BSTR Path, BSTR Name, BSTR *Result) { - BSTR ret; - TRACE("%p %s %s %p\n", iface, debugstr_w(Path), debugstr_w(Name), Result); if (!Result) return E_POINTER; - if (Path && Name) - { - int path_len = SysStringLen(Path), name_len = SysStringLen(Name); - - /* if both parts have backslashes strip one from Path */ - if (Path[path_len-1] == '\\' && Name[0] == '\\') - { - path_len -= 1; - - ret = SysAllocStringLen(NULL, path_len + name_len); - if (ret) - { - lstrcpyW(ret, Path); - ret[path_len] = 0; - lstrcatW(ret, Name); - } - } - else if (Path[path_len-1] != '\\' && Name[0] != '\\') - { - ret = SysAllocStringLen(NULL, path_len + name_len + 1); - if (ret) - { - lstrcpyW(ret, Path); - if (Path[path_len-1] != ':') - wcscat(ret, L"\\"); - lstrcatW(ret, Name); - } - } - else - { - ret = SysAllocStringLen(NULL, path_len + name_len); - if (ret) - { - lstrcpyW(ret, Path); - lstrcatW(ret, Name); - } - } - } - else if (Path || Name) - ret = SysAllocString(Path ? Path : Name); - else - ret = SysAllocStringLen(NULL, 0); - - if (!ret) return E_OUTOFMEMORY; - *Result = ret; - - return S_OK; + return build_path(Path, Name, Result); } static HRESULT WINAPI filesys_GetDriveName(IFileSystem3 *iface, BSTR path, BSTR *drive) -- 2.31.1