diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2012-10-23 11:56:40 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2012-12-06 20:30:30 +0100 |
commit | e4c3e73623b9c546d4b356f7c207b0d2c8c3f750 (patch) | |
tree | a7958961a2f2c16766e4fbb9b666d39524c29f90 /libmsi | |
parent | d9990bc09cafe1edd2175d4c6b6bb9d103dff30a (diff) | |
download | msitools-e4c3e73623b9c546d4b356f7c207b0d2c8c3f750.tar.gz msitools-e4c3e73623b9c546d4b356f7c207b0d2c8c3f750.tar.xz msitools-e4c3e73623b9c546d4b356f7c207b0d2c8c3f750.zip |
do not use lstr functions
Diffstat (limited to 'libmsi')
-rw-r--r-- | libmsi/database.c | 68 | ||||
-rw-r--r-- | libmsi/msipriv.h | 18 | ||||
-rw-r--r-- | libmsi/record.c | 14 | ||||
-rw-r--r-- | libmsi/suminfo.c | 10 | ||||
-rw-r--r-- | libmsi/table.c | 36 | ||||
-rw-r--r-- | libmsi/unicode.h | 14 |
6 files changed, 94 insertions, 66 deletions
diff --git a/libmsi/database.c b/libmsi/database.c index 84f0663..95efc62 100644 --- a/libmsi/database.c +++ b/libmsi/database.c @@ -410,11 +410,11 @@ unsigned MSI_OpenDatabaseW(const WCHAR *szDBPath, const WCHAR *szPersist, Libmsi if (!strchrW( save_path, '\\' )) { GetCurrentDirectoryW( MAX_PATH, path ); - lstrcatW( path, szBackSlash ); - lstrcatW( path, save_path ); + strcatW( path, szBackSlash ); + strcatW( path, save_path ); } else - lstrcpyW( path, save_path ); + strcpyW( path, save_path ); db->path = strdupW( path ); db->media_transform_offset = MSI_INITIAL_MEDIA_TRANSFORM_OFFSET; @@ -607,7 +607,7 @@ static WCHAR *msi_build_createsql_prelude(WCHAR *table) static const WCHAR create_fmt[] = {'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','%','s','`',' ','(',' ',0}; - size = sizeof(create_fmt)/sizeof(create_fmt[0]) + lstrlenW(table) - 2; + size = sizeof(create_fmt)/sizeof(create_fmt[0]) + strlenW(table) - 2; prelude = msi_alloc(size * sizeof(WCHAR)); if (!prelude) return NULL; @@ -655,22 +655,22 @@ static WCHAR *msi_build_createsql_columns(WCHAR **columns_data, WCHAR **types, u switch (types[i][0]) { case 'l': - lstrcpyW(extra, type_notnull); + strcpyW(extra, type_notnull); /* fall through */ case 'L': - lstrcatW(extra, localizable); + strcatW(extra, localizable); type = type_char; sprintfW(size, size_fmt, ptr); break; case 's': - lstrcpyW(extra, type_notnull); + strcpyW(extra, type_notnull); /* fall through */ case 'S': type = type_char; sprintfW(size, size_fmt, ptr); break; case 'i': - lstrcpyW(extra, type_notnull); + strcpyW(extra, type_notnull); /* fall through */ case 'I': if (len <= 2) @@ -685,7 +685,7 @@ static WCHAR *msi_build_createsql_columns(WCHAR **columns_data, WCHAR **types, u } break; case 'v': - lstrcpyW(extra, type_notnull); + strcpyW(extra, type_notnull); /* fall through */ case 'V': type = type_object; @@ -697,7 +697,7 @@ static WCHAR *msi_build_createsql_columns(WCHAR **columns_data, WCHAR **types, u } sprintfW(expanded, column_fmt, columns_data[i], type, size, extra, comma); - sql_size += lstrlenW(expanded); + sql_size += strlenW(expanded); p = msi_realloc(columns, sql_size * sizeof(WCHAR)); if (!p) @@ -707,7 +707,7 @@ static WCHAR *msi_build_createsql_columns(WCHAR **columns_data, WCHAR **types, u } columns = p; - lstrcatW(columns, expanded); + strcatW(columns, expanded); } return columns; @@ -724,7 +724,7 @@ static WCHAR *msi_build_createsql_postlude(WCHAR **primary_keys, unsigned num_ke static const WCHAR postlude_fmt[] = {'P','R','I','M','A','R','Y',' ','K','E','Y',' ','%','s',')',0}; for (i = 0, size = 1; i < num_keys; i++) - size += lstrlenW(key_fmt) + lstrlenW(primary_keys[i]) - 2; + size += strlenW(key_fmt) + strlenW(primary_keys[i]) - 2; keys = msi_alloc(size * sizeof(WCHAR)); if (!keys) @@ -732,7 +732,7 @@ static WCHAR *msi_build_createsql_postlude(WCHAR **primary_keys, unsigned num_ke for (i = 0, ptr = keys; i < num_keys; i++) { - key_size = lstrlenW(key_fmt) + lstrlenW(primary_keys[i]) -2; + key_size = strlenW(key_fmt) + strlenW(primary_keys[i]) -2; sprintfW(ptr, key_fmt, primary_keys[i]); ptr += key_size; } @@ -740,7 +740,7 @@ static WCHAR *msi_build_createsql_postlude(WCHAR **primary_keys, unsigned num_ke /* remove final ', ' */ *(ptr - 2) = '\0'; - size = lstrlenW(postlude_fmt) + size - 1; + size = strlenW(postlude_fmt) + size - 1; postlude = msi_alloc(size * sizeof(WCHAR)); if (!postlude) goto done; @@ -769,14 +769,14 @@ static unsigned msi_add_table_to_db(LibmsiDatabase *db, WCHAR **columns, WCHAR * if (!prelude || !columns_sql || !postlude) goto done; - size = lstrlenW(prelude) + lstrlenW(columns_sql) + lstrlenW(postlude) + 1; + size = strlenW(prelude) + strlenW(columns_sql) + strlenW(postlude) + 1; create_sql = msi_alloc(size * sizeof(WCHAR)); if (!create_sql) goto done; - lstrcpyW(create_sql, prelude); - lstrcatW(create_sql, columns_sql); - lstrcatW(create_sql, postlude); + strcpyW(create_sql, prelude); + strcatW(create_sql, columns_sql); + strcatW(create_sql, postlude); r = MSI_DatabaseOpenViewW( db, create_sql, &view ); if (r != ERROR_SUCCESS) @@ -800,12 +800,12 @@ static WCHAR *msi_import_stream_filename(const WCHAR *path, const WCHAR *name) WCHAR *fullname; WCHAR *ptr; - len = lstrlenW(path) + lstrlenW(name) + 1; + len = strlenW(path) + strlenW(name) + 1; fullname = msi_alloc(len*sizeof(WCHAR)); if (!fullname) return NULL; - lstrcpyW( fullname, path ); + strcpyW( fullname, path ); /* chop off extension from path */ ptr = strrchrW(fullname, '.'); @@ -815,7 +815,7 @@ static WCHAR *msi_import_stream_filename(const WCHAR *path, const WCHAR *name) return NULL; } *ptr++ = '\\'; - lstrcpyW( ptr, name ); + strcpyW( ptr, name ); return fullname; } @@ -936,14 +936,14 @@ static unsigned MSI_DatabaseImport(LibmsiDatabase *db, const WCHAR *folder, cons if( folder == NULL || file == NULL ) return ERROR_INVALID_PARAMETER; - len = lstrlenW(folder) + lstrlenW(szBackSlash) + lstrlenW(file) + 1; + len = strlenW(folder) + strlenW(szBackSlash) + strlenW(file) + 1; path = msi_alloc( len * sizeof(WCHAR) ); if (!path) return ERROR_OUTOFMEMORY; - lstrcpyW( path, folder ); - lstrcatW( path, szBackSlash ); - lstrcatW( path, file ); + strcpyW( path, folder ); + strcatW( path, szBackSlash ); + strcatW( path, file ); data = msi_read_text_archive( path, &len ); @@ -1133,7 +1133,7 @@ static unsigned msi_export_forcecodepage( HANDLE handle, unsigned codepage ) sprintf( data, fmt, codepage ); - sz = lstrlenA(data) + 1; + sz = strlen(data) + 1; if (!WriteFile(handle, data, sz, &sz, NULL)) return ERROR_FUNCTION_FAILED; @@ -1159,14 +1159,14 @@ static unsigned MSI_DatabaseExport( LibmsiDatabase *db, const WCHAR *table, if( folder == NULL || file == NULL ) return ERROR_INVALID_PARAMETER; - len = lstrlenW(folder) + lstrlenW(file) + 2; + len = strlenW(folder) + strlenW(file) + 2; filename = msi_alloc(len * sizeof (WCHAR)); if (!filename) return ERROR_OUTOFMEMORY; - lstrcpyW( filename, folder ); - lstrcatW( filename, szBackSlash ); - lstrcatW( filename, file ); + strcpyW( filename, folder ); + strcatW( filename, szBackSlash ); + strcatW( filename, file ); handle = CreateFileW( filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); @@ -1482,9 +1482,9 @@ static WCHAR *get_key_value(LibmsiQuery *view, const WCHAR *key, LibmsiRecord *r if (!val) return NULL; - lstrcpyW(val, szQuote); + strcpyW(val, szQuote); r = MSI_RecordGetStringW(rec, i, val+1, &sz); - lstrcpyW(val+1+sz, szQuote); + strcpyW(val+1+sz, szQuote); } else { @@ -1547,7 +1547,7 @@ static WCHAR *create_diff_row_query(LibmsiDatabase *merge, LibmsiQuery *view, setptr = keyset; oldsize = size; - size += lstrlenW(setptr) + lstrlenW(key) + lstrlenW(val) - 4; + size += strlenW(setptr) + strlenW(key) + strlenW(val) - 4; clause = msi_realloc(clause, size * sizeof (WCHAR)); if (!clause) { @@ -1559,7 +1559,7 @@ static WCHAR *create_diff_row_query(LibmsiDatabase *merge, LibmsiQuery *view, msi_free(val); } - size = lstrlenW(fmt) + lstrlenW(table) + lstrlenW(clause) + 1; + size = strlenW(fmt) + strlenW(table) + strlenW(clause) + 1; query = msi_alloc(size * sizeof(WCHAR)); if (!query) goto done; diff --git a/libmsi/msipriv.h b/libmsi/msipriv.h index aff1951..03f696a 100644 --- a/libmsi/msipriv.h +++ b/libmsi/msipriv.h @@ -549,6 +549,20 @@ static inline bool msi_free( void *mem ) free(mem); } +static inline char *strcpynA( char *dst, const char *src, unsigned count ) +{ + char *d = dst; + const char *s = src; + + while ((count > 1) && *s) + { + count--; + *d++ = *s++; + } + if (count) *d = 0; + return dst; +} + static inline char *strdupWtoA( const WCHAR *str ) { char *ret = NULL; @@ -579,9 +593,9 @@ static inline WCHAR *strdupW( const WCHAR *src ) { WCHAR *dest; if (!src) return NULL; - dest = msi_alloc( (lstrlenW(src)+1)*sizeof(WCHAR) ); + dest = msi_alloc( (strlenW(src)+1)*sizeof(WCHAR) ); if (dest) - lstrcpyW(dest, src); + strcpyW(dest, src); return dest; } diff --git a/libmsi/record.c b/libmsi/record.c index 4f6ba9b..33c8bc6 100644 --- a/libmsi/record.c +++ b/libmsi/record.c @@ -389,9 +389,9 @@ unsigned MSI_RecordGetStringA(LibmsiRecord *rec, unsigned iField, { case LIBMSI_FIELD_TYPE_INT: wsprintfA(buffer, "%d", rec->fields[iField].u.iVal); - len = lstrlenA( buffer ); + len = strlen( buffer ); if (szValue) - lstrcpynA(szValue, buffer, *pcchValue); + strcpynA(szValue, buffer, *pcchValue); break; case LIBMSI_FIELD_TYPE_WSTR: len = WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1, @@ -472,14 +472,14 @@ unsigned MSI_RecordGetStringW(LibmsiRecord *rec, unsigned iField, { case LIBMSI_FIELD_TYPE_INT: wsprintfW(buffer, szFormat, rec->fields[iField].u.iVal); - len = lstrlenW( buffer ); + len = strlenW( buffer ); if (szValue) - lstrcpynW(szValue, buffer, *pcchValue); + strcpynW(szValue, buffer, *pcchValue); break; case LIBMSI_FIELD_TYPE_WSTR: - len = lstrlenW( rec->fields[iField].u.szwVal ); + len = strlenW( rec->fields[iField].u.szwVal ); if (szValue) - lstrcpynW(szValue, rec->fields[iField].u.szwVal, *pcchValue); + strcpynW(szValue, rec->fields[iField].u.szwVal, *pcchValue); break; case LIBMSI_FIELD_TYPE_NULL: if( szValue && *pcchValue > 0 ) @@ -538,7 +538,7 @@ static unsigned MSI_RecordDataSize(LibmsiRecord *rec, unsigned iField) case LIBMSI_FIELD_TYPE_INT: return sizeof (int); case LIBMSI_FIELD_TYPE_WSTR: - return lstrlenW( rec->fields[iField].u.szwVal ); + return strlenW( rec->fields[iField].u.szwVal ); case LIBMSI_FIELD_TYPE_NULL: break; case LIBMSI_FIELD_TYPE_STREAM: diff --git a/libmsi/suminfo.c b/libmsi/suminfo.c index 84347aa..0b97a2a 100644 --- a/libmsi/suminfo.c +++ b/libmsi/suminfo.c @@ -324,7 +324,7 @@ static unsigned write_filetime( uint8_t *data, unsigned ofs, const FILETIME *ft static unsigned write_string( uint8_t *data, unsigned ofs, const char *str ) { - unsigned len = lstrlenA( str ) + 1; + unsigned len = strlen( str ) + 1; write_dword( data, ofs, len ); if( data ) memcpy( &data[ofs + 4], str, len ); @@ -582,9 +582,9 @@ static unsigned get_prop( LibmsiObject *handle, unsigned uiProperty, unsigned *p } else { - len = lstrlenA( prop->pszVal ); + len = strlen( prop->pszVal ); if( str->str.a ) - lstrcpynA(str->str.a, prop->pszVal, *pcchValueBuf ); + strcpynA(str->str.a, prop->pszVal, *pcchValueBuf ); } if (len >= *pcchValueBuf) ret = ERROR_MORE_DATA; @@ -722,9 +722,9 @@ static unsigned set_prop( LibmsiSummaryInfo *si, unsigned uiProperty, unsigned t } else { - len = lstrlenA( str->str.a ) + 1; + len = strlen( str->str.a ) + 1; prop->pszVal = msi_alloc( len ); - lstrcpyA( prop->pszVal, str->str.a ); + strcpy( prop->pszVal, str->str.a ); } break; } diff --git a/libmsi/table.c b/libmsi/table.c index 4a9f37b..9bc61e8 100644 --- a/libmsi/table.c +++ b/libmsi/table.c @@ -133,7 +133,7 @@ WCHAR *encode_streamname(bool bTable, const WCHAR *in) WCHAR *p; if( !bTable ) - count = lstrlenW( in )+2; + count = strlenW( in )+2; if (!(out = msi_alloc( count*sizeof(WCHAR) ))) return NULL; p = out; @@ -597,7 +597,7 @@ static unsigned get_table( LibmsiDatabase *db, const WCHAR *name, LibmsiTable ** } /* nonexistent tables should be interpreted as empty tables */ - table = msi_alloc( sizeof(LibmsiTable) + lstrlenW( name ) * sizeof(WCHAR) ); + table = msi_alloc( sizeof(LibmsiTable) + strlenW( name ) * sizeof(WCHAR) ); if (!table) return ERROR_FUNCTION_FAILED; @@ -607,7 +607,7 @@ static unsigned get_table( LibmsiDatabase *db, const WCHAR *name, LibmsiTable ** table->colinfo = NULL; table->col_count = 0; table->persistent = LIBMSI_CONDITION_TRUE; - lstrcpyW( table->name, name ); + strcpyW( table->name, name ); if (!strcmpW( name, szTables ) || !strcmpW( name, szColumns )) table->persistent = LIBMSI_CONDITION_NONE; @@ -734,7 +734,7 @@ unsigned msi_create_table( LibmsiDatabase *db, const WCHAR *name, column_info *c return ERROR_BAD_QUERY_SYNTAX; } - table = msi_alloc( sizeof (LibmsiTable) + lstrlenW(name)*sizeof (WCHAR) ); + table = msi_alloc( sizeof (LibmsiTable) + strlenW(name)*sizeof (WCHAR) ); if( !table ) return ERROR_FUNCTION_FAILED; @@ -745,7 +745,7 @@ unsigned msi_create_table( LibmsiDatabase *db, const WCHAR *name, column_info *c table->colinfo = NULL; table->col_count = 0; table->persistent = persistent; - lstrcpyW( table->name, name ); + strcpyW( table->name, name ); for( col = col_info; col; col = col->next ) table->col_count++; @@ -1064,7 +1064,7 @@ static unsigned msi_stream_name( const LibmsiTableVIEW *tv, unsigned row, WCHAR TRACE("%p %d\n", tv, row); - len = lstrlenW( tv->name ) + 1; + len = strlenW( tv->name ) + 1; stname = msi_alloc( len*sizeof(WCHAR) ); if ( !stname ) { @@ -1072,7 +1072,7 @@ static unsigned msi_stream_name( const LibmsiTableVIEW *tv, unsigned row, WCHAR goto err; } - lstrcpyW( stname, tv->name ); + strcpyW( stname, tv->name ); for ( i = 0; i < tv->num_cols; i++ ) { @@ -1115,7 +1115,7 @@ static unsigned msi_stream_name( const LibmsiTableVIEW *tv, unsigned row, WCHAR sval = number; } - len += lstrlenW( szDot ) + lstrlenW( sval ); + len += strlenW( szDot ) + strlenW( sval ); p = msi_realloc ( stname, len*sizeof(WCHAR) ); if ( !p ) { @@ -1124,8 +1124,8 @@ static unsigned msi_stream_name( const LibmsiTableVIEW *tv, unsigned row, WCHAR } stname = p; - lstrcatW( stname, szDot ); - lstrcatW( stname, sval ); + strcatW( stname, szDot ); + strcatW( stname, sval ); } else continue; @@ -2140,7 +2140,7 @@ unsigned TABLE_CreateView( LibmsiDatabase *db, const WCHAR *name, LibmsiView **v else if ( !strcmpW( name, szStorages ) ) return STORAGES_CreateView( db, view ); - sz = sizeof *tv + lstrlenW(name)*sizeof name[0] ; + sz = sizeof *tv + strlenW(name)*sizeof name[0] ; tv = msi_alloc_zero( sz ); if( !tv ) return ERROR_FUNCTION_FAILED; @@ -2165,7 +2165,7 @@ unsigned TABLE_CreateView( LibmsiDatabase *db, const WCHAR *name, LibmsiView **v TRACE("%s one row is %d bytes\n", debugstr_w(name), tv->row_size ); *view = (LibmsiView*) tv; - lstrcpyW( tv->name, name ); + strcpyW( tv->name, name ); return ERROR_SUCCESS; } @@ -2242,7 +2242,7 @@ static unsigned msi_record_encoded_stream_name( const LibmsiTableVIEW *tv, Libms TRACE("%p %p\n", tv, rec); - len = lstrlenW( tv->name ) + 1; + len = strlenW( tv->name ) + 1; stname = msi_alloc( len*sizeof(WCHAR) ); if ( !stname ) { @@ -2250,7 +2250,7 @@ static unsigned msi_record_encoded_stream_name( const LibmsiTableVIEW *tv, Libms goto err; } - lstrcpyW( stname, tv->name ); + strcpyW( stname, tv->name ); for ( i = 0; i < tv->num_cols; i++ ) { @@ -2263,7 +2263,7 @@ static unsigned msi_record_encoded_stream_name( const LibmsiTableVIEW *tv, Libms goto err; } - len += lstrlenW( szDot ) + lstrlenW ( sval ); + len += strlenW( szDot ) + strlenW ( sval ); p = msi_realloc ( stname, len*sizeof(WCHAR) ); if ( !p ) { @@ -2272,8 +2272,8 @@ static unsigned msi_record_encoded_stream_name( const LibmsiTableVIEW *tv, Libms } stname = p; - lstrcatW( stname, szDot ); - lstrcatW( stname, sval ); + strcatW( stname, szDot ); + strcatW( stname, sval ); msi_free( sval ); } @@ -2626,7 +2626,7 @@ static unsigned msi_table_load_transform( LibmsiDatabase *db, IStorage *stg, if (strcmpW( coltable, table )) { colcol = 0; - lstrcpyW( coltable, table ); + strcpyW( coltable, table ); } /* fix nul column numbers */ diff --git a/libmsi/unicode.h b/libmsi/unicode.h index 7b4e6f7..d134f3e 100644 --- a/libmsi/unicode.h +++ b/libmsi/unicode.h @@ -56,6 +56,20 @@ static inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src ) /* strncpy doesn't do what you think, don't use it */ #define strncpyW(d,s,n) error do_not_use_strncpyW_use_lstrcpynW_or_memcpy_instead +static inline WCHAR *strcpynW( WCHAR *dst, const WCHAR *src, unsigned count ) +{ + WCHAR *d = dst; + const WCHAR *s = src; + + while ((count > 1) && *s) + { + count--; + *d++ = *s++; + } + if (count) *d = 0; + return dst; +} + static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 ) { while (*str1 && (*str1 == *str2)) { str1++; str2++; } |