Robert Wilhelm : scrrun: Extract code to new helper function build_path.

Alexandre Julliard julliard at winehq.org
Wed Dec 1 15:23:50 CST 2021


Module: wine
Branch: master
Commit: fe7f21b0ab8b2bf97d39bdadc25b46b33c1fb68f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fe7f21b0ab8b2bf97d39bdadc25b46b33c1fb68f

Author: Robert Wilhelm <robert.wilhelm at gmx.net>
Date:   Sun Nov 28 22:57:55 2021 +0100

scrrun: Extract code to new helper function build_path.

Signed-off-by: Robert Wilhelm <robert.wilhelm at gmx.net>
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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)




More information about the wine-cvs mailing list