From: Alex Henrie alexhenrie24@gmail.com
--- programs/cabarc/cabarc.c | 42 +++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 24 deletions(-)
diff --git a/programs/cabarc/cabarc.c b/programs/cabarc/cabarc.c index c4622e43046..6d104a8fef4 100644 --- a/programs/cabarc/cabarc.c +++ b/programs/cabarc/cabarc.c @@ -47,12 +47,7 @@ static WCHAR **opt_files;
static void * CDECL cab_alloc( ULONG size ) { - return HeapAlloc( GetProcessHeap(), 0, size ); -} - -static void CDECL cab_free( void *ptr ) -{ - HeapFree( GetProcessHeap(), 0, ptr ); + return malloc( size ); }
static WCHAR *strdupAtoW( UINT cp, const char *str ) @@ -61,7 +56,7 @@ static WCHAR *strdupAtoW( UINT cp, const char *str ) if (str) { DWORD len = MultiByteToWideChar( cp, 0, str, -1, NULL, 0 ); - if ((ret = cab_alloc( len * sizeof(WCHAR) ))) + if ((ret = malloc( len * sizeof(WCHAR) ))) MultiByteToWideChar( cp, 0, str, -1, ret, len ); } return ret; @@ -73,7 +68,7 @@ static char *strdupWtoA( UINT cp, const WCHAR *str ) if (str) { DWORD len = WideCharToMultiByte( cp, 0, str, -1, NULL, 0, NULL, NULL ); - if ((ret = cab_alloc( len ))) + if ((ret = malloc( len ))) WideCharToMultiByte( cp, 0, str, -1, ret, len, NULL, NULL ); } return ret; @@ -236,21 +231,21 @@ static INT_PTR CDECL fci_get_open_info( char *name, USHORT *date, USHORT *time, { *err = GetLastError(); WINE_ERR( "failed to open %s: error %u\n", wine_dbgstr_w(nameW), *err ); - cab_free( nameW ); + free( nameW ); return -1; } if (!GetFileInformationByHandle( handle, &info )) { *err = GetLastError(); CloseHandle( handle ); - cab_free( nameW ); + free( nameW ); return -1; } FileTimeToDosDateTime( &info.ftLastWriteTime, date, time ); *attribs = info.dwFileAttributes & (_A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH); for (p = nameW; *p; p++) if (*p >= 0x80) break; if (*p) *attribs |= _A_NAME_IS_UTF; - cab_free( nameW ); + free( nameW ); return (INT_PTR)handle; }
@@ -291,8 +286,7 @@ static void create_directories( const WCHAR *name ) WCHAR *path, *p;
/* create the directory/directories */ - path = cab_alloc( (lstrlenW(name) + 1) * sizeof(WCHAR) ); - lstrcpyW(path, name); + path = wcsdup( name );
p = wcschr(path, '\'); while (p != NULL) @@ -303,7 +297,7 @@ static void create_directories( const WCHAR *name ) *p = '\'; p = wcschr(p+1, '\'); } - cab_free( path ); + free( path ); }
/* check if file name matches against one of the files specification */ @@ -349,7 +343,7 @@ static INT_PTR CDECL list_notify( FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pf } wprintf( L"%s\n", nameW ); } - cab_free( nameW ); + free( nameW ); return 0; default: WINE_FIXME( "Unexpected notification type %d.\n", fdint ); @@ -361,7 +355,7 @@ static int list_cabinet( char *cab_dir ) { ERF erf; int ret = 0; - HFDI fdi = FDICreate( cab_alloc, cab_free, fdi_open, fdi_read, + HFDI fdi = FDICreate( cab_alloc, free, fdi_open, fdi_read, fdi_write, fdi_close, fdi_lseek, cpuUNKNOWN, &erf );
if (!FDICopy( fdi, opt_cab_file, cab_dir, 0, list_notify, NULL, NULL )) ret = GetLastError(); @@ -394,7 +388,7 @@ static INT_PTR CDECL extract_notify( FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION
if (opt_dest_dir) { - path = cab_alloc( (lstrlenW(opt_dest_dir) + lstrlenW(file) + 1) * sizeof(WCHAR) ); + path = malloc( (wcslen(opt_dest_dir) + wcslen(file) + 1) * sizeof(WCHAR) ); lstrcpyW( path, opt_dest_dir ); lstrcatW( path, file ); } @@ -410,8 +404,8 @@ static INT_PTR CDECL extract_notify( FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION } else ret = 0;
- cab_free( nameW ); - if (path != file) cab_free( path ); + free( nameW ); + if (path != file) free( path ); return ret;
case fdintCLOSE_FILE_INFO: @@ -435,7 +429,7 @@ static int extract_cabinet( char *cab_dir ) { ERF erf; int ret = 0; - HFDI fdi = FDICreate( cab_alloc, cab_free, fdi_open, fdi_read, + HFDI fdi = FDICreate( cab_alloc, free, fdi_open, fdi_read, fdi_write, fdi_close, fdi_lseek, cpuUNKNOWN, &erf );
if (!FDICopy( fdi, opt_cab_file, cab_dir, 0, extract_notify, NULL, NULL )) @@ -464,7 +458,7 @@ static BOOL add_file( HFCI fci, WCHAR *name ) } ret = FCIAddFile( fci, path, filename, FALSE, fci_get_next_cab, fci_status, fci_get_open_info, opt_compression ); - cab_free( path ); + free( path ); return ret; }
@@ -475,7 +469,7 @@ static BOOL add_directory( HFCI fci, WCHAR *dir ) WIN32_FIND_DATAW data; BOOL ret = TRUE;
- if (!(buffer = cab_alloc( (lstrlenW(dir) + MAX_PATH + 2) * sizeof(WCHAR) ))) return FALSE; + if (!(buffer = malloc( (wcslen(dir) + MAX_PATH + 2) * sizeof(WCHAR) ))) return FALSE; lstrcpyW( buffer, dir ); p = buffer + lstrlenW( buffer ); if (p > buffer && p[-1] != '\') *p++ = '\'; @@ -498,7 +492,7 @@ static BOOL add_directory( HFCI fci, WCHAR *dir ) } while (FindNextFileW( handle, &data )); FindClose( handle ); } - cab_free( buffer ); + free( buffer ); return TRUE; }
@@ -543,7 +537,7 @@ static int new_cabinet( char *cab_dir ) strcat( cab.szCabPath, "\" ); format_cab_name( cab.szCab, 1, opt_cab_file );
- fci = FCICreate( &erf, fci_file_placed, cab_alloc, cab_free,fci_open, fci_read, + fci = FCICreate( &erf, fci_file_placed, cab_alloc, free, fci_open, fci_read, fci_write, fci_close, fci_lseek, fci_delete, fci_get_temp, &cab, NULL );
for (file = opt_files; *file; file++)
I think it's easier to keep the wrappers, because of FDI/FCI interface.
On Mon Nov 27 17:55:38 2023 +0000, Nikolay Sivov wrote:
I think it's easier to keep the wrappers, because of FDI/FCI interface.
Do we have to use the wrappers everywhere? It would be nice to be able to use wcsdup in create_directories.
Alternatively, we could rename cab_alloc to fci_fdi_alloc to make it clear that it is only used with FCICreate and FDICreate.
On Mon Nov 27 17:55:38 2023 +0000, Alex Henrie wrote:
Do we have to use the wrappers everywhere? It would be nice to be able to use wcsdup in create_directories. Alternatively, we could rename cab_alloc to fci_fdi_alloc to make it clear that it is only used with FCICreate and FDICreate.
We already have cab_alloc()/cab_free(), no need to rename anything. Just keep them for FCICreate/FDICreate.