Vincent Povirk : ole32: Change the base IStorage filename to a pointer type .
Alexandre Julliard
julliard at winehq.org
Tue Dec 8 11:10:35 CST 2009
Module: wine
Branch: master
Commit: 9300a92ccccf794208882bf12c5b1e0a3f9a0cae
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9300a92ccccf794208882bf12c5b1e0a3f9a0cae
Author: Vincent Povirk <vincent at codeweavers.com>
Date: Mon Dec 7 14:53:36 2009 -0600
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.
---
dlls/ole32/storage32.c | 17 +++++-----
dlls/ole32/storage32.h | 2 +-
dlls/ole32/tests/storage32.c | 71 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 80 insertions(+), 10 deletions(-)
diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c
index 3263221..2015eaf 100644
--- a/dlls/ole32/storage32.c
+++ b/dlls/ole32/storage32.c
@@ -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.
*/
diff --git a/dlls/ole32/storage32.h b/dlls/ole32/storage32.h
index a087e0d..fdac6a5 100644
--- a/dlls/ole32/storage32.h
+++ b/dlls/ole32/storage32.h
@@ -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 */
diff --git a/dlls/ole32/tests/storage32.c b/dlls/ole32/tests/storage32.c
index 6e222c7..b5ecf22 100644
--- a/dlls/ole32/tests/storage32.c
+++ b/dlls/ole32/tests/storage32.c
@@ -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();
}
More information about the wine-cvs
mailing list