Skip to content

Commit ae589cd

Browse files
committed
Update minizip module
1 parent c98e802 commit ae589cd

File tree

10 files changed

+703
-937
lines changed

10 files changed

+703
-937
lines changed

source/logging/appenders/minizip/crypt.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,20 @@
3232
/***********************************************************************
3333
* Return the next byte in the pseudo-random sequence
3434
*/
35-
static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
36-
{
35+
static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
3736
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
3837
* unpredictable manner on 16-bit systems; not a problem
3938
* with any known compiler so far, though */
4039

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

4545
/***********************************************************************
4646
* Update the encryption keys with the next byte of plain text
4747
*/
48-
static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
49-
{
48+
static int update_keys(unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c) {
5049
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
5150
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
5251
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
@@ -62,8 +61,7 @@ static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
6261
* Initialize the encryption keys and the random header according to
6362
* the given password.
6463
*/
65-
static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
66-
{
64+
static void init_keys(const char* passwd, unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
6765
*(pkeys+0) = 305419896L;
6866
*(pkeys+1) = 591751049L;
6967
*(pkeys+2) = 878082192L;
@@ -77,24 +75,23 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcr
7775
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
7876

7977
#define zencode(pkeys,pcrc_32_tab,c,t) \
80-
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
78+
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), (Byte)t^(c))
8179

8280
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
8381

8482
#define RAND_HEAD_LEN 12
8583
/* "last resort" source for second part of crypt seed pattern */
8684
# ifndef ZCR_SEED2
87-
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
85+
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
8886
# endif
8987

90-
static int crypthead(const char* passwd, /* password string */
91-
unsigned char* buf, /* where to write header */
92-
int bufSize,
93-
unsigned long* pkeys,
94-
const z_crc_t* pcrc_32_tab,
95-
unsigned long crcForCrypting)
96-
{
97-
int n; /* index in random header */
88+
static unsigned crypthead(const char* passwd, /* password string */
89+
unsigned char* buf, /* where to write header */
90+
int bufSize,
91+
unsigned long* pkeys,
92+
const z_crc_t* pcrc_32_tab,
93+
unsigned long crcForCrypting) {
94+
unsigned n; /* index in random header */
9895
int t; /* temporary */
9996
int c; /* random byte */
10097
unsigned char header[RAND_HEAD_LEN-2]; /* random header */

source/logging/appenders/minizip/ioapi.c

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define _CRT_SECURE_NO_WARNINGS
1515
#endif
1616

17-
#if defined(__APPLE__) || defined(IOAPI_NO_64)
17+
#if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
1818
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
1919
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
2020
#define FTELLO_FUNC(stream) ftello(stream)
@@ -28,8 +28,7 @@
2828

2929
#include "ioapi.h"
3030

31-
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
32-
{
31+
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc, const void*filename, int mode) {
3332
if (pfilefunc->zfile_func64.zopen64_file != NULL)
3433
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
3534
else
@@ -38,8 +37,7 @@ voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename
3837
}
3938
}
4039

41-
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
42-
{
40+
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) {
4341
if (pfilefunc->zfile_func64.zseek64_file != NULL)
4442
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
4543
else
@@ -52,25 +50,22 @@ long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZP
5250
}
5351
}
5452

55-
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
56-
{
53+
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc, voidpf filestream) {
5754
if (pfilefunc->zfile_func64.zseek64_file != NULL)
5855
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
5956
else
6057
{
61-
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
58+
uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
6259
if ((tell_uLong) == MAXU32)
6360
return (ZPOS64_T)-1;
6461
else
6562
return tell_uLong;
6663
}
6764
}
6865

69-
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
70-
{
66+
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32, const zlib_filefunc_def* p_filefunc32) {
7167
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
7268
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
73-
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
7469
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
7570
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
7671
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
@@ -84,18 +79,10 @@ void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef
8479

8580

8681

87-
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
88-
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
89-
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
90-
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
91-
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
92-
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
93-
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
94-
95-
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
96-
{
82+
static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char* filename, int mode) {
9783
FILE* file = NULL;
9884
const char* mode_fopen = NULL;
85+
(void)opaque;
9986
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
10087
mode_fopen = "rb";
10188
else
@@ -110,10 +97,10 @@ static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, in
11097
return file;
11198
}
11299

113-
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
114-
{
100+
static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void* filename, int mode) {
115101
FILE* file = NULL;
116102
const char* mode_fopen = NULL;
103+
(void)opaque;
117104
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
118105
mode_fopen = "rb";
119106
else
@@ -129,39 +116,39 @@ static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename,
129116
}
130117

131118

132-
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
133-
{
119+
static uLong ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uLong size) {
134120
uLong ret;
121+
(void)opaque;
135122
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
136123
return ret;
137124
}
138125

139-
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
140-
{
126+
static uLong ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) {
141127
uLong ret;
128+
(void)opaque;
142129
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
143130
return ret;
144131
}
145132

146-
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
147-
{
133+
static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream) {
148134
long ret;
135+
(void)opaque;
149136
ret = ftell((FILE *)stream);
150137
return ret;
151138
}
152139

153140

154-
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
155-
{
141+
static ZPOS64_T ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream) {
156142
ZPOS64_T ret;
157-
ret = FTELLO_FUNC((FILE *)stream);
143+
(void)opaque;
144+
ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
158145
return ret;
159146
}
160147

161-
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
162-
{
148+
static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) {
163149
int fseek_origin=0;
164150
long ret;
151+
(void)opaque;
165152
switch (origin)
166153
{
167154
case ZLIB_FILEFUNC_SEEK_CUR :
@@ -176,15 +163,15 @@ static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs
176163
default: return -1;
177164
}
178165
ret = 0;
179-
if (fseek((FILE *)stream, offset, fseek_origin) != 0)
166+
if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
180167
ret = -1;
181168
return ret;
182169
}
183170

184-
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
185-
{
171+
static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) {
186172
int fseek_origin=0;
187173
long ret;
174+
(void)opaque;
188175
switch (origin)
189176
{
190177
case ZLIB_FILEFUNC_SEEK_CUR :
@@ -200,30 +187,28 @@ static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T
200187
}
201188
ret = 0;
202189

203-
if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
190+
if(FSEEKO_FUNC((FILE *)stream, (z_off64_t)offset, fseek_origin) != 0)
204191
ret = -1;
205192

206193
return ret;
207194
}
208195

209196

210-
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
211-
{
197+
static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream) {
212198
int ret;
199+
(void)opaque;
213200
ret = fclose((FILE *)stream);
214201
return ret;
215202
}
216203

217-
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
218-
{
204+
static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream) {
219205
int ret;
206+
(void)opaque;
220207
ret = ferror((FILE *)stream);
221208
return ret;
222209
}
223210

224-
void fill_fopen_filefunc (pzlib_filefunc_def)
225-
zlib_filefunc_def* pzlib_filefunc_def;
226-
{
211+
void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def) {
227212
pzlib_filefunc_def->zopen_file = fopen_file_func;
228213
pzlib_filefunc_def->zread_file = fread_file_func;
229214
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
@@ -234,8 +219,7 @@ void fill_fopen_filefunc (pzlib_filefunc_def)
234219
pzlib_filefunc_def->opaque = NULL;
235220
}
236221

237-
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
238-
{
222+
void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def) {
239223
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
240224
pzlib_filefunc_def->zread_file = fread_file_func;
241225
pzlib_filefunc_def->zwrite_file = fwrite_file_func;

source/logging/appenders/minizip/ioapi.h

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#define ftello64 ftell
5151
#define fseeko64 fseek
5252
#else
53-
#ifdef __FreeBSD__
53+
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
5454
#define fopen64 fopen
5555
#define ftello64 ftello
5656
#define fseeko64 fseeko
@@ -82,7 +82,7 @@
8282
#include "mz64conf.h"
8383
#endif
8484

85-
/* a type choosen by DEFINE */
85+
/* a type chosen by DEFINE */
8686
#ifdef HAVE_64BIT_INT_CUSTOM
8787
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
8888
#else
@@ -91,8 +91,7 @@ typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
9191
typedef uint64_t ZPOS64_T;
9292
#else
9393

94-
/* Maximum unsigned 32-bit value used as placeholder for zip64 */
95-
#define MAXU32 0xffffffff
94+
9695

9796
#if defined(_MSC_VER) || defined(__BORLANDC__)
9897
typedef unsigned __int64 ZPOS64_T;
@@ -102,7 +101,10 @@ typedef unsigned long long int ZPOS64_T;
102101
#endif
103102
#endif
104103

105-
104+
/* Maximum unsigned 32-bit value used as placeholder for zip64 */
105+
#ifndef MAXU32
106+
#define MAXU32 (0xffffffff)
107+
#endif
106108

107109
#ifdef __cplusplus
108110
extern "C" {
@@ -132,17 +134,17 @@ extern "C" {
132134

133135

134136

135-
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
136-
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
137-
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
138-
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
139-
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
137+
typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char* filename, int mode);
138+
typedef uLong (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uLong size);
139+
typedef uLong (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void* buf, uLong size);
140+
typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream);
141+
typedef int (ZCALLBACK *testerror_file_func) (voidpf opaque, voidpf stream);
140142

141-
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
142-
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
143+
typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream);
144+
typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin);
143145

144146

145-
/* here is the "old" 32 bits structure structure */
147+
/* here is the "old" 32 bits structure */
146148
typedef struct zlib_filefunc_def_s
147149
{
148150
open_file_func zopen_file;
@@ -155,9 +157,9 @@ typedef struct zlib_filefunc_def_s
155157
voidpf opaque;
156158
} zlib_filefunc_def;
157159

158-
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
159-
typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
160-
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
160+
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream);
161+
typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin);
162+
typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void* filename, int mode);
161163

162164
typedef struct zlib_filefunc64_def_s
163165
{
@@ -171,8 +173,8 @@ typedef struct zlib_filefunc64_def_s
171173
voidpf opaque;
172174
} zlib_filefunc64_def;
173175

174-
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
175-
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
176+
void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def);
177+
void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def);
176178

177179
/* now internal definition, only for zip.c and unzip.h */
178180
typedef struct zlib_filefunc64_32_def_s
@@ -191,11 +193,11 @@ typedef struct zlib_filefunc64_32_def_s
191193
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
192194
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
193195

194-
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
195-
long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
196-
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
196+
voidpf call_zopen64(const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode);
197+
long call_zseek64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin);
198+
ZPOS64_T call_ztell64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream);
197199

198-
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
200+
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
199201

200202
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
201203
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))

0 commit comments

Comments
 (0)