Commit 9300a92c authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

ole32: Change the base IStorage filename to a pointer type.

The maximum size of the name returned by Stat() on a top-level storage has nothing to do with DIRENTRY_NAME_BUFFER_LEN. Windows can return longer names and probably has a limit of MAX_PATH. Also, Stat always returns an absolute pathname, so we don't need a special case in StgOpenStorage.
parent efbd38ae
......@@ -2242,6 +2242,7 @@ static HRESULT StorageImpl_Construct(
HRESULT hr = S_OK;
DirEntry currentEntry;
DirRef currentEntryRef;
WCHAR fullpath[MAX_PATH];
if ( FAILED( validateSTGM(openFlags) ))
return STG_E_INVALIDFLAG;
......@@ -2272,15 +2273,19 @@ static HRESULT StorageImpl_Construct(
This->hFile = hFile;
if(pwcsName) {
if (!GetFullPathNameW(pwcsName, MAX_PATH, fullpath, NULL))
{
lstrcpynW(fullpath, pwcsName, MAX_PATH);
}
This->pwcsName = HeapAlloc(GetProcessHeap(), 0,
(lstrlenW(pwcsName)+1)*sizeof(WCHAR));
(lstrlenW(fullpath)+1)*sizeof(WCHAR));
if (!This->pwcsName)
{
hr = STG_E_INSUFFICIENTMEMORY;
goto end;
}
strcpyW(This->pwcsName, pwcsName);
lstrcpynW(This->base.filename, pwcsName, DIRENTRY_NAME_BUFFER_LEN);
strcpyW(This->pwcsName, fullpath);
This->base.filename = This->pwcsName;
}
/*
......@@ -5857,7 +5862,6 @@ HRESULT WINAPI StgOpenStorage(
HANDLE hFile = 0;
DWORD shareMode;
DWORD accessMode;
WCHAR fullname[MAX_PATH];
TRACE("(%s, %p, %x, %p, %d, %p)\n",
debugstr_w(pwcsName), pstgPriority, grfMode,
......@@ -6011,11 +6015,6 @@ HRESULT WINAPI StgOpenStorage(
goto end;
}
/* prepare the file name string given in lieu of the root property name */
GetFullPathNameW(pwcsName, MAX_PATH, fullname, NULL);
memcpy(newStorage->base.filename, fullname, DIRENTRY_NAME_BUFFER_LEN);
newStorage->base.filename[DIRENTRY_NAME_BUFFER_LEN-1] = '\0';
/*
* Get an "out" pointer for the caller.
*/
......
......@@ -239,7 +239,7 @@ struct StorageBaseImpl
DWORD stateBits;
/* If set, this overrides the root storage name returned by IStorage_Stat */
WCHAR filename[DIRENTRY_NAME_BUFFER_LEN];
LPCWSTR filename;
BOOL create; /* Was the storage created or opened.
The behaviour of STGM_SIMPLE depends on this */
......
......@@ -2466,6 +2466,76 @@ static void test_rename(void)
ok( r == TRUE, "deleted file\n");
}
static void test_toplevel_stat(void)
{
IStorage *stg = NULL;
HRESULT r;
STATSTG stat;
WCHAR prev_dir[MAX_PATH];
WCHAR temp[MAX_PATH];
WCHAR full_path[MAX_PATH];
LPWSTR rel_path;
DeleteFileA(filenameA);
r = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE |
STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
ok(r==S_OK, "StgCreateDocfile failed\n");
r = IStorage_Stat( stg, &stat, STATFLAG_DEFAULT );
ok(!lstrcmpW(stat.pwcsName, filename), "expected %s, got %s\n",
wine_dbgstr_w(filename), wine_dbgstr_w(stat.pwcsName));
CoTaskMemFree(stat.pwcsName);
IStorage_Release( stg );
r = StgOpenStorage( filename, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, NULL, 0, &stg);
ok(r==S_OK, "StgOpenStorage failed with error 0x%08x\n", r);
r = IStorage_Stat( stg, &stat, STATFLAG_DEFAULT );
ok(!lstrcmpW(stat.pwcsName, filename), "expected %s, got %s\n",
wine_dbgstr_w(filename), wine_dbgstr_w(stat.pwcsName));
CoTaskMemFree(stat.pwcsName);
IStorage_Release( stg );
DeleteFileA(filenameA);
/* Stat always returns the full path, even for files opened with a relative path. */
GetCurrentDirectoryW(MAX_PATH, prev_dir);
GetTempPathW(MAX_PATH, temp);
SetCurrentDirectoryW(temp);
GetFullPathNameW(filename, MAX_PATH, full_path, &rel_path);
r = StgCreateDocfile( rel_path, STGM_CREATE | STGM_SHARE_EXCLUSIVE |
STGM_READWRITE |STGM_TRANSACTED, 0, &stg);
ok(r==S_OK, "StgCreateDocfile failed\n");
r = IStorage_Stat( stg, &stat, STATFLAG_DEFAULT );
ok(!lstrcmpW(stat.pwcsName, filename), "expected %s, got %s\n",
wine_dbgstr_w(filename), wine_dbgstr_w(stat.pwcsName));
CoTaskMemFree(stat.pwcsName);
IStorage_Release( stg );
r = StgOpenStorage( rel_path, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, NULL, 0, &stg);
ok(r==S_OK, "StgOpenStorage failed with error 0x%08x\n", r);
r = IStorage_Stat( stg, &stat, STATFLAG_DEFAULT );
ok(!lstrcmpW(stat.pwcsName, filename), "expected %s, got %s\n",
wine_dbgstr_w(filename), wine_dbgstr_w(stat.pwcsName));
CoTaskMemFree(stat.pwcsName);
IStorage_Release( stg );
SetCurrentDirectoryW(prev_dir);
DeleteFileA(filenameA);
}
START_TEST(storage32)
{
CHAR temp[MAX_PATH];
......@@ -2503,4 +2573,5 @@ START_TEST(storage32)
test_copyto_iidexclusions_storage();
test_copyto_iidexclusions_stream();
test_rename();
test_toplevel_stat();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment