[PATCH 6/8] scrrun: Move code to new helper function get_file_name().

Robert Wilhelm wine at gitlab.winehq.org
Wed Jun 29 10:47:07 CDT 2022


From: Robert Wilhelm <robert.wilhelm at gmx.net>

Signed-off-by: Robert Wilhelm <robert.wilhelm at gmx.net>
---
 dlls/scrrun/filesystem.c | 42 ++++++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 12 deletions(-)

diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index 6ffebc0af12..197fe9f3625 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -3301,10 +3301,37 @@ static HRESULT WINAPI filesys_GetParentFolderName(IFileSystem3 *iface, BSTR Path
     return S_OK;
 }
 
+static HRESULT get_file_name(const WCHAR *path, int *start, int *end)
+{
+    int s,e;
+
+    if(!path)
+        return 0;
+
+    for(e=lstrlenW(path)-1; e>=0; e--)
+        if(path[e]!='/' && path[e]!='\\')
+            break;
+
+    for(s=e; s>=0; s--)
+        if(path[s]=='/' || path[s]=='\\')
+            break;
+
+    s++;
+
+    if(s>e || (s==0 && e==1 && path[1]==':')) {
+        return E_FAIL;
+    }
+
+    *start = s;
+    *end = e;
+
+    return S_OK;
+}
+
 static HRESULT WINAPI filesys_GetFileName(IFileSystem3 *iface, BSTR Path,
                                             BSTR *pbstrResult)
 {
-    int i, end;
+    int start=0, end=0;
 
     TRACE("%p %s %p\n", iface, debugstr_w(Path), pbstrResult);
 
@@ -3316,21 +3343,12 @@ static HRESULT WINAPI filesys_GetFileName(IFileSystem3 *iface, BSTR Path,
         return S_OK;
     }
 
-    for(end=lstrlenW(Path)-1; end>=0; end--)
-        if(Path[end]!='/' && Path[end]!='\\')
-            break;
-
-    for(i=end; i>=0; i--)
-        if(Path[i]=='/' || Path[i]=='\\')
-            break;
-    i++;
-
-    if(i>end || (i==0 && end==1 && Path[1]==':')) {
+    if (FAILED(get_file_name( Path, &start, &end))) {
         *pbstrResult = NULL;
         return S_OK;
     }
 
-    *pbstrResult = SysAllocStringLen(Path+i, end-i+1);
+    *pbstrResult = SysAllocStringLen(Path+start, end-start+1);
     if(!*pbstrResult)
         return E_OUTOFMEMORY;
     return S_OK;
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/343



More information about the wine-devel mailing list