diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c index 6af81235633..90999517b62 100644 --- a/dlls/scrrun/filesystem.c +++ b/dlls/scrrun/filesystem.c @@ -780,9 +780,36 @@ static HRESULT WINAPI filesys_GetParentFolderName(IFileSystem3 *iface, BSTR Path static HRESULT WINAPI filesys_GetFileName(IFileSystem3 *iface, BSTR Path, BSTR *pbstrResult) { - FIXME("%p %s %p\n", iface, debugstr_w(Path), pbstrResult); + int i, end; - return E_NOTIMPL; + TRACE("%p %s %p\n", iface, debugstr_w(Path), pbstrResult); + + if(!pbstrResult) + return E_POINTER; + + if(!Path) { + *pbstrResult = NULL; + return S_OK; + } + + for(end=strlenW(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]==':')) { + *pbstrResult = NULL; + return S_OK; + } + + *pbstrResult = SysAllocStringLen(Path+i, end-i+1); + if(!*pbstrResult) + return E_OUTOFMEMORY; + return S_OK; } static HRESULT WINAPI filesys_GetBaseName(IFileSystem3 *iface, BSTR Path, diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c index 3f0f95966c6..940356f0373 100644 --- a/dlls/scrrun/tests/filesystem.c +++ b/dlls/scrrun/tests/filesystem.c @@ -302,6 +302,49 @@ static void test_GetParentFolderName(void) } } +static void test_GetFileName(void) +{ + static const WCHAR path1[] = {'a',0}; + static const WCHAR path2[] = {'a','/','a','.','b',0}; + static const WCHAR path3[] = {'a','\\',0}; + static const WCHAR path4[] = {'c',':',0}; + static const WCHAR path5[] = {'/','\\',0}; + static const WCHAR result2[] = {'a','.','b',0}; + static const WCHAR result3[] = {'a',0}; + + static const struct { + const WCHAR *path; + const WCHAR *result; + } tests[] = { + {NULL, NULL}, + {path1, path1}, + {path2, result2}, + {path3, result3}, + {path4, NULL}, + {path5, NULL} + }; + + BSTR path, result; + HRESULT hr; + int i; + + hr = IFileSystem3_GetFileName(fs3, NULL, NULL); + ok(hr == E_POINTER, "GetFileName returned %x, expected E_POINTER\n", hr); + + for(i=0; i