diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2012-10-23 12:49:25 +0200 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2012-12-06 20:30:30 +0100 |
| commit | c87cdd87005f65bc458a3d6167aa7e2a73ed47b5 (patch) | |
| tree | 6f44473fa7cb4126e7633e69e4647c8590d62cc7 | |
| parent | 110f65204388339e16f739afc24ddbb2826f0b71 (diff) | |
make MsiOpenDatabase ASCII only
Removes DeleteFile, LPCTSTR, GetCurrentDirectoryW.
| -rw-r--r-- | include/libmsi.h | 14 | ||||
| -rw-r--r-- | libmsi/database.c | 82 | ||||
| -rw-r--r-- | libmsi/msipriv.h | 6 | ||||
| -rw-r--r-- | tests/testdatabase.c | 6 |
4 files changed, 37 insertions, 71 deletions
diff --git a/include/libmsi.h b/include/libmsi.h index 8f06853..188fd69 100644 --- a/include/libmsi.h +++ b/include/libmsi.h @@ -58,11 +58,11 @@ typedef enum LibmsiModify LIBMSI_MODIFY_VALIDATE_DELETE = 11 } LibmsiModify; -#define LIBMSI_DB_OPEN_READONLY (LPCTSTR)0 -#define LIBMSI_DB_OPEN_TRANSACT (LPCTSTR)1 -#define LIBMSI_DB_OPEN_DIRECT (LPCTSTR)2 -#define LIBMSI_DB_OPEN_CREATE (LPCTSTR)3 -#define LIBMSI_DB_OPEN_CREATEDIRECT (LPCTSTR)4 +#define LIBMSI_DB_OPEN_READONLY (const char *)0 +#define LIBMSI_DB_OPEN_TRANSACT (const char *)1 +#define LIBMSI_DB_OPEN_DIRECT (const char *)2 +#define LIBMSI_DB_OPEN_CREATE (const char *)3 +#define LIBMSI_DB_OPEN_CREATEDIRECT (const char *)4 #define LIBMSI_DB_OPEN_PATCHFILE 32 / sizeof(*LIBMSI_DB_OPEN_READONLY) @@ -216,9 +216,7 @@ unsigned MsiDatabaseImportA(LibmsiObject *, const char *, const char *); unsigned MsiDatabaseImportW(LibmsiObject *, const WCHAR *, const WCHAR *); #define MsiDatabaseImport WINELIB_NAME_AW(MsiDatabaseImport) -unsigned MsiOpenDatabaseW(const WCHAR *, const WCHAR *, LibmsiObject **); -unsigned MsiOpenDatabaseA(const char *, const char *, LibmsiObject **); -#define MsiOpenDatabase WINELIB_NAME_AW(MsiOpenDatabase) +unsigned MsiOpenDatabase(const char *, const char *, LibmsiObject **); LibmsiCondition MsiDatabaseIsTablePersistentA(LibmsiObject *, const char *); LibmsiCondition MsiDatabaseIsTablePersistentW(LibmsiObject *, const WCHAR *); diff --git a/libmsi/database.c b/libmsi/database.c index 95efc62..b053f83 100644 --- a/libmsi/database.c +++ b/libmsi/database.c @@ -20,6 +20,7 @@ #include <stdarg.h> #include <stdio.h> +#include <unistd.h> #define COBJMACROS #define NONAMELESSUNION @@ -251,7 +252,7 @@ static VOID MSI_CloseDatabase( LibmsiObject *arg ) IStorage_Release( db->storage ); if (db->deletefile) { - DeleteFileW( db->deletefile ); + unlink( db->deletefile ); msi_free( db->deletefile ); } } @@ -293,17 +294,17 @@ static HRESULT db_initialize( IStorage *stg, const GUID *clsid ) return S_OK; } -unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, LibmsiDatabase **pdb) +unsigned MSI_OpenDatabase(const char *szDBPath, const char *szPersist, LibmsiDatabase **pdb) { IStorage *stg = NULL; HRESULT r; LibmsiDatabase *db = NULL; unsigned ret = ERROR_FUNCTION_FAILED; - const WCHAR *szMode; - const WCHAR *save_path; + WCHAR *szwDBPath; + const char *szMode; STATSTG stat; bool created = false, patch = false; - WCHAR path[MAX_PATH]; + char path[MAX_PATH]; TRACE("%s %s\n",debugstr_w(szDBPath),debugstr_w(szPersist) ); @@ -318,11 +319,10 @@ unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, Libmsi patch = true; } - save_path = szDBPath; szMode = szPersist; if( !IS_INTMSIDBOPEN(szPersist) ) { - if (!CopyFileW( szDBPath, szPersist, false )) + if (!CopyFileA( szDBPath, szPersist, false )) return ERROR_OPEN_FAILED; szDBPath = szPersist; @@ -330,14 +330,15 @@ unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, Libmsi created = true; } + szwDBPath = strdupAtoW(szDBPath); if( szPersist == LIBMSI_DB_OPEN_READONLY ) { - r = StgOpenStorage( szDBPath, NULL, + r = StgOpenStorage( szwDBPath, NULL, STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE, NULL, 0, &stg); } else if( szPersist == LIBMSI_DB_OPEN_CREATE ) { - r = StgCreateDocfile( szDBPath, + r = StgCreateDocfile( szwDBPath, STGM_CREATE|STGM_TRANSACTED|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg ); if( SUCCEEDED(r) ) @@ -346,7 +347,7 @@ unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, Libmsi } else if( szPersist == LIBMSI_DB_OPEN_CREATEDIRECT ) { - r = StgCreateDocfile( szDBPath, + r = StgCreateDocfile( szwDBPath, STGM_CREATE|STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg ); if( SUCCEEDED(r) ) @@ -355,12 +356,12 @@ unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, Libmsi } else if( szPersist == LIBMSI_DB_OPEN_TRANSACT ) { - r = StgOpenStorage( szDBPath, NULL, + r = StgOpenStorage( szwDBPath, NULL, STGM_TRANSACTED|STGM_READWRITE|STGM_SHARE_DENY_WRITE, NULL, 0, &stg); } else if( szPersist == LIBMSI_DB_OPEN_DIRECT ) { - r = StgOpenStorage( szDBPath, NULL, + r = StgOpenStorage( szwDBPath, NULL, STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg); } else @@ -368,10 +369,11 @@ unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, Libmsi ERR("unknown flag %p\n",szPersist); return ERROR_INVALID_PARAMETER; } + msi_free(szwDBPath); if( FAILED( r ) || !stg ) { - WARN("open failed r = %08x for %s\n", r, debugstr_w(szDBPath)); + WARN("open failed r = %08x for %s\n", r, debugstr_a(szDBPath)); return ERROR_FUNCTION_FAILED; } @@ -407,16 +409,16 @@ unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, Libmsi goto end; } - if (!strchrW( save_path, '\\' )) + if (!strchr( szDBPath, '\\' )) { - GetCurrentDirectoryW( MAX_PATH, path ); - strcatW( path, szBackSlash ); - strcatW( path, save_path ); + getcwd( path, MAX_PATH ); + strcat( path, "\\" ); + strcat( path, szDBPath ); } else - strcpyW( path, save_path ); + strcpy( path, szDBPath ); - db->path = strdupW( path ); + db->path = strdup( path ); db->media_transform_offset = MSI_INITIAL_MEDIA_TRANSFORM_OFFSET; db->media_transform_disk_id = MSI_INITIAL_MEDIA_TRANSFORM_DISKID; @@ -426,7 +428,7 @@ unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, Libmsi db->storage = stg; db->mode = szMode; if (created) - db->deletefile = strdupW( szDBPath ); + db->deletefile = strdup( szDBPath ); list_init( &db->tables ); list_init( &db->transforms ); list_init( &db->streams ); @@ -450,14 +452,14 @@ end: return ret; } -unsigned MsiOpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, LibmsiObject **phDB) +unsigned MsiOpenDatabase(const char *szDBPath, const char *szPersist, LibmsiObject **phDB) { LibmsiDatabase *db; unsigned ret; - TRACE("%s %s %p\n",debugstr_w(szDBPath),debugstr_w(szPersist), phDB); + TRACE("%s %s %p\n",debugstr_a(szDBPath),debugstr_a(szPersist), phDB); - ret = MSI_OpenDatabaseW( szDBPath, szPersist, &db ); + ret = MSI_OpenDatabase( szDBPath, szPersist, &db ); if( ret == ERROR_SUCCESS ) { *phDB = &db->hdr; @@ -466,40 +468,6 @@ unsigned MsiOpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, LibmsiO return ret; } -unsigned MsiOpenDatabaseA(const char *szDBPath, const char *szPersist, LibmsiObject **phDB) -{ - HRESULT r = ERROR_FUNCTION_FAILED; - WCHAR *szwDBPath = NULL; - WCHAR *szwPersist = NULL; - - TRACE("%s %s %p\n", debugstr_a(szDBPath), debugstr_a(szPersist), phDB); - - if( szDBPath ) - { - szwDBPath = strdupAtoW( szDBPath ); - if( !szwDBPath ) - goto end; - } - - if( !IS_INTMSIDBOPEN(szPersist) ) - { - szwPersist = strdupAtoW( szPersist ); - if( !szwPersist ) - goto end; - } - else - szwPersist = (WCHAR *)(uintptr_t)szPersist; - - r = MsiOpenDatabaseW( szwDBPath, szwPersist, phDB ); - -end: - if( !IS_INTMSIDBOPEN(szPersist) ) - msi_free( szwPersist ); - msi_free( szwDBPath ); - - return r; -} - static WCHAR *msi_read_text_archive(const WCHAR *path, unsigned *len) { HANDLE file; diff --git a/libmsi/msipriv.h b/libmsi/msipriv.h index 03f696a..bda3ae8 100644 --- a/libmsi/msipriv.h +++ b/libmsi/msipriv.h @@ -77,9 +77,9 @@ typedef struct LibmsiDatabase IStorage *storage; string_table *strings; unsigned bytes_per_strref; - WCHAR *path; - WCHAR *deletefile; - const WCHAR *mode; + char *path; + char *deletefile; + const char *mode; unsigned media_transform_offset; unsigned media_transform_disk_id; struct list tables; diff --git a/tests/testdatabase.c b/tests/testdatabase.c index e976f4f..68bd396 100644 --- a/tests/testdatabase.c +++ b/tests/testdatabase.c @@ -2132,7 +2132,7 @@ static void test_suminfo_import(void) GetCurrentDirectoryA(MAX_PATH, CURR_DIR); - r = MsiOpenDatabaseA(msifile, LIBMSI_DB_OPEN_CREATE, &hdb); + r = MsiOpenDatabase(msifile, LIBMSI_DB_OPEN_CREATE, &hdb); ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r); r = add_table_to_db(hdb, suminfo); @@ -2255,7 +2255,7 @@ static void test_msiimport(void) GetCurrentDirectoryA(MAX_PATH, CURR_DIR); - r = MsiOpenDatabaseA(msifile, LIBMSI_DB_OPEN_CREATE, &hdb); + r = MsiOpenDatabase(msifile, LIBMSI_DB_OPEN_CREATE, &hdb); ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); r = add_table_to_db(hdb, test_data); @@ -9202,7 +9202,7 @@ static void test_embedded_nulls(void) LibmsiObject *hrec; char buffer[32]; - r = MsiOpenDatabaseA( msifile, LIBMSI_DB_OPEN_CREATE, &hdb ); + r = MsiOpenDatabase( msifile, LIBMSI_DB_OPEN_CREATE, &hdb ); ok( r == ERROR_SUCCESS, "failed to open database %u\n", r ); GetCurrentDirectoryA( MAX_PATH, CURR_DIR ); |
