Skip to content

Commit

Permalink
Clang-format style changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Nov 1, 2024
1 parent 483950d commit 2c51fa7
Show file tree
Hide file tree
Showing 47 changed files with 1,239 additions and 1,395 deletions.
42 changes: 20 additions & 22 deletions compat/crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,49 @@
# endif
#endif

#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
#define CRC32(c, b) ((*(pcrc_32_tab + (((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))

/***************************************************************************/
/* Return the next byte in the pseudo-random sequence */

static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
static int decrypt_byte(unsigned long *pkeys, const z_crc_t *pcrc_32_tab) {
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */

(void)pcrc_32_tab;
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
temp = ((unsigned)(*(pkeys + 2)) & 0xffff) | 2;
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
}

/***************************************************************************/
/* Update the encryption keys with the next byte of plain text */

static int update_keys(unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c) {
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
static int update_keys(unsigned long *pkeys, const z_crc_t *pcrc_32_tab, int c) {
(*(pkeys + 0)) = CRC32((*(pkeys + 0)), c);
(*(pkeys + 1)) += (*(pkeys + 0)) & 0xff;
(*(pkeys + 1)) = (*(pkeys + 1)) * 134775813L + 1;
{
register int keyshift = (int)((*(pkeys+1)) >> 24);
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
register int keyshift = (int)((*(pkeys + 1)) >> 24);
(*(pkeys + 2)) = CRC32((*(pkeys + 2)), keyshift);
}
return c;
}


/***************************************************************************/
/* Initialize the encryption keys and the random header according to the password. */

static void init_keys(const char* passwd, unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
*(pkeys+0) = 305419896L;
*(pkeys+1) = 591751049L;
*(pkeys+2) = 878082192L;
static void init_keys(const char *passwd, unsigned long *pkeys, const z_crc_t *pcrc_32_tab) {
*(pkeys + 0) = 305419896L;
*(pkeys + 1) = 591751049L;
*(pkeys + 2) = 878082192L;
while (*passwd != '\0') {
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
update_keys(pkeys, pcrc_32_tab, (int)*passwd);
passwd++;
}
}

#define zdecode(pkeys,pcrc_32_tab,c) \
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
#define zdecode(pkeys, pcrc_32_tab, c) (update_keys(pkeys, pcrc_32_tab, c ^= decrypt_byte(pkeys, pcrc_32_tab)))

#define zencode(pkeys,pcrc_32_tab,c,t) \
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), (Byte)t^(c))
#define zencode(pkeys, pcrc_32_tab, c, t) \
(t = decrypt_byte(pkeys, pcrc_32_tab), update_keys(pkeys, pcrc_32_tab, c), (Byte)t ^ (c))
32 changes: 15 additions & 17 deletions compat/ioapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "ioapi.h"

typedef struct mz_stream_ioapi_s {
mz_stream stream;
void *handle;
zlib_filefunc_def filefunc;
mz_stream stream;
void *handle;
zlib_filefunc_def filefunc;
zlib_filefunc64_def filefunc64;
} mz_stream_ioapi;

Expand All @@ -24,20 +24,18 @@ static int32_t mz_stream_ioapi_error(void *stream);

/***************************************************************************/

static mz_stream_vtbl mz_stream_ioapi_vtbl = {
mz_stream_ioapi_open,
mz_stream_ioapi_is_open,
mz_stream_ioapi_read,
mz_stream_ioapi_write,
mz_stream_ioapi_tell,
mz_stream_ioapi_seek,
mz_stream_ioapi_close,
mz_stream_ioapi_error,
mz_stream_ioapi_create,
mz_stream_ioapi_delete,
NULL,
NULL
};
static mz_stream_vtbl mz_stream_ioapi_vtbl = {mz_stream_ioapi_open,
mz_stream_ioapi_is_open,
mz_stream_ioapi_read,
mz_stream_ioapi_write,
mz_stream_ioapi_tell,
mz_stream_ioapi_seek,
mz_stream_ioapi_close,
mz_stream_ioapi_error,
mz_stream_ioapi_create,
mz_stream_ioapi_delete,
NULL,
NULL};

/***************************************************************************/

Expand Down
77 changes: 37 additions & 40 deletions compat/ioapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
typedef uint64_t ZPOS64_T;

#ifndef ZEXPORT
#define ZEXPORT extern
# define ZEXPORT extern
#endif

#ifdef __cplusplus
Expand All @@ -20,59 +20,56 @@ extern "C" {

/***************************************************************************/

#define ZLIB_FILEFUNC_SEEK_SET (0)
#define ZLIB_FILEFUNC_SEEK_CUR (1)
#define ZLIB_FILEFUNC_SEEK_END (2)
#define ZLIB_FILEFUNC_SEEK_SET (0)
#define ZLIB_FILEFUNC_SEEK_CUR (1)
#define ZLIB_FILEFUNC_SEEK_END (2)

#define ZLIB_FILEFUNC_MODE_READ (1)
#define ZLIB_FILEFUNC_MODE_WRITE (2)
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
#define ZLIB_FILEFUNC_MODE_READ (1)
#define ZLIB_FILEFUNC_MODE_WRITE (2)
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)

#define ZLIB_FILEFUNC_MODE_EXISTING (4)
#define ZLIB_FILEFUNC_MODE_CREATE (8)
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
#define ZLIB_FILEFUNC_MODE_CREATE (8)

#ifndef ZCALLBACK
#define ZCALLBACK
# define ZCALLBACK
#endif

/***************************************************************************/

typedef void* (ZCALLBACK *open_file_func) (void *opaque, const char *filename, int mode);
typedef void* (ZCALLBACK *open64_file_func) (void *opaque, const void *filename, int mode);
typedef unsigned long (ZCALLBACK *read_file_func) (void *opaque, void *stream, void* buf, unsigned long size);
typedef unsigned long (ZCALLBACK *write_file_func) (void *opaque, void *stream, const void* buf,
unsigned long size);
typedef int (ZCALLBACK *close_file_func) (void *opaque, void *stream);
typedef int (ZCALLBACK *testerror_file_func)(void *opaque, void *stream);
typedef long (ZCALLBACK *tell_file_func) (void *opaque, void *stream);
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (void *opaque, void *stream);
typedef long (ZCALLBACK *seek_file_func) (void *opaque, void *stream, unsigned long offset, int origin);
typedef long (ZCALLBACK *seek64_file_func) (void *opaque, void *stream, ZPOS64_T offset, int origin);
typedef void *(ZCALLBACK *open_file_func)(void *opaque, const char *filename, int mode);
typedef void *(ZCALLBACK *open64_file_func)(void *opaque, const void *filename, int mode);
typedef unsigned long(ZCALLBACK *read_file_func)(void *opaque, void *stream, void *buf, unsigned long size);
typedef unsigned long(ZCALLBACK *write_file_func)(void *opaque, void *stream, const void *buf, unsigned long size);
typedef int(ZCALLBACK *close_file_func)(void *opaque, void *stream);
typedef int(ZCALLBACK *testerror_file_func)(void *opaque, void *stream);
typedef long(ZCALLBACK *tell_file_func)(void *opaque, void *stream);
typedef ZPOS64_T(ZCALLBACK *tell64_file_func)(void *opaque, void *stream);
typedef long(ZCALLBACK *seek_file_func)(void *opaque, void *stream, unsigned long offset, int origin);
typedef long(ZCALLBACK *seek64_file_func)(void *opaque, void *stream, ZPOS64_T offset, int origin);

/***************************************************************************/

typedef struct zlib_filefunc_def_s
{
open_file_func zopen_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell_file_func ztell_file;
seek_file_func zseek_file;
close_file_func zclose_file;
typedef struct zlib_filefunc_def_s {
open_file_func zopen_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell_file_func ztell_file;
seek_file_func zseek_file;
close_file_func zclose_file;
testerror_file_func zerror_file;
void* opaque;
void *opaque;
} zlib_filefunc_def;

typedef struct zlib_filefunc64_def_s
{
open64_file_func zopen64_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell64_file_func ztell64_file;
seek64_file_func zseek64_file;
close_file_func zclose_file;
typedef struct zlib_filefunc64_def_s {
open64_file_func zopen64_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell64_file_func ztell64_file;
seek64_file_func zseek64_file;
close_file_func zclose_file;
testerror_file_func zerror_file;
void* opaque;
void *opaque;
} zlib_filefunc64_def;

/***************************************************************************/
Expand Down Expand Up @@ -101,4 +98,4 @@ void mz_stream_ioapi_delete(void **stream);
}
#endif

#endif
#endif
48 changes: 23 additions & 25 deletions compat/unzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
/***************************************************************************/

typedef struct mz_unzip_compat_s {
void *stream;
void *handle;
void *stream;
void *handle;
uint64_t entry_index;
int64_t entry_pos;
int64_t total_out;
int64_t entry_pos;
int64_t total_out;
} mz_unzip_compat;

/***************************************************************************/
Expand All @@ -41,7 +41,7 @@ unzFile unzOpen64(const void *path) {
}

unzFile unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def) {
unzFile unz = NULL;
unzFile unz = NULL;
void *stream = NULL;

if (pzlib_filefunc_def) {
Expand Down Expand Up @@ -114,14 +114,14 @@ unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def) {
return unz;
}

void* unzGetHandle_MZ(unzFile file) {
void *unzGetHandle_MZ(unzFile file) {
mz_unzip_compat *compat = (mz_unzip_compat *)file;
if (!compat)
return NULL;
return compat->handle;
}

void* unzGetStream_MZ(unzFile file) {
void *unzGetStream_MZ(unzFile file) {
mz_unzip_compat *compat = (mz_unzip_compat *)file;
if (!compat)
return NULL;
Expand Down Expand Up @@ -190,7 +190,7 @@ int unzClose_MZ(unzFile file) {
return err;
}

int unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32) {
int unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info32) {
mz_unzip_compat *compat = (mz_unzip_compat *)file;
unz_global_info64 global_info64;
int32_t err = MZ_OK;
Expand Down Expand Up @@ -330,9 +330,8 @@ static void unzConvertTimeToUnzTime(time_t time, tm_unz *tmu_date) {
tmu_date->tm_year += 1900;
}

int unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
unsigned long filename_size, void *extrafield, unsigned long extrafield_size, char *comment,
unsigned long comment_size) {
int unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename, unsigned long filename_size,
void *extrafield, unsigned long extrafield_size, char *comment, unsigned long comment_size) {
mz_unzip_compat *compat = (mz_unzip_compat *)file;
mz_zip_file *file_info = NULL;
uint16_t bytes_to_copy = 0;
Expand Down Expand Up @@ -390,9 +389,9 @@ int unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filenam
return err;
}

int unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_info, char *filename,
unsigned long filename_size, void *extrafield, unsigned long extrafield_size, char *comment,
unsigned long comment_size) {
int unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename, unsigned long filename_size,
void *extrafield, unsigned long extrafield_size, char *comment,
unsigned long comment_size) {
mz_unzip_compat *compat = (mz_unzip_compat *)file;
mz_zip_file *file_info = NULL;
uint16_t bytes_to_copy = 0;
Expand Down Expand Up @@ -470,11 +469,11 @@ int unzGoToNextFile(unzFile file) {
}

#if !defined(MZ_COMPAT_VERSION) || MZ_COMPAT_VERSION < 110
#ifdef WIN32
# define UNZ_DEFAULT_IGNORE_CASE 1
#else
# define UNZ_DEFAULT_IGNORE_CASE 0
#endif
# ifdef WIN32
# define UNZ_DEFAULT_IGNORE_CASE 1
# else
# define UNZ_DEFAULT_IGNORE_CASE 0
# endif

int unzLocateFile(unzFile file, const char *filename, unzFileNameCase filename_case) {
mz_unzip_compat *compat = (mz_unzip_compat *)file;
Expand Down Expand Up @@ -513,9 +512,9 @@ int unzLocateFile(unzFile file, const char *filename, unzFileNameCase filename_c
return err;
}
#else
int unzLocateFile(unzFile file, const char* filename, unzFileNameComparer filename_compare_func) {
mz_compat* compat = (mz_compat*)file;
mz_zip_file* file_info = NULL;
int unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func) {
mz_unzip_compat *compat = (mz_unzip_compat *)file;
mz_zip_file *file_info = NULL;
uint64_t preserve_index = 0;
int32_t err = MZ_OK;
int32_t result = 0;
Expand All @@ -533,8 +532,7 @@ int unzLocateFile(unzFile file, const char* filename, unzFileNameComparer filena

if ((intptr_t)filename_compare_func > 2) {
result = filename_compare_func(file, filename, file_info->filename);
}
else {
} else {
int32_t case_sensitive = (int32_t)(intptr_t)filename_compare_func;
result = mz_path_compare_wc(filename, file_info->filename, !case_sensitive);
}
Expand Down Expand Up @@ -727,7 +725,7 @@ int unzeof(unzFile file) {
return 0;
}

void* unzGetStream(unzFile file) {
void *unzGetStream(unzFile file) {
mz_unzip_compat *compat = (mz_unzip_compat *)file;
if (!compat)
return NULL;
Expand Down
Loading

0 comments on commit 2c51fa7

Please sign in to comment.