Skip to content

Commit

Permalink
Improve portability of contrib/minizip.
Browse files Browse the repository at this point in the history
  • Loading branch information
madler committed Feb 10, 2021
1 parent 506424c commit 0530dbc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions contrib/minizip/crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
* 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;
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
Expand Down
10 changes: 10 additions & 0 deletions contrib/minizip/ioapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));

static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
{
(void)opaque;
FILE* file = NULL;
const char* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
Expand All @@ -112,6 +113,7 @@ static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, in

static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
{
(void)opaque;
FILE* file = NULL;
const char* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
Expand All @@ -131,20 +133,23 @@ static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename,

static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
{
(void)opaque;
uLong ret;
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}

static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
{
(void)opaque;
uLong ret;
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}

static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
{
(void)opaque;
long ret;
ret = ftell((FILE *)stream);
return ret;
Expand All @@ -153,13 +158,15 @@ static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)

static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
{
(void)opaque;
ZPOS64_T ret;
ret = FTELLO_FUNC((FILE *)stream);
return ret;
}

static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
{
(void)opaque;
int fseek_origin=0;
long ret;
switch (origin)
Expand All @@ -183,6 +190,7 @@ static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs

static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
{
(void)opaque;
int fseek_origin=0;
long ret;
switch (origin)
Expand All @@ -209,13 +217,15 @@ static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T

static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
{
(void)opaque;
int ret;
ret = fclose((FILE *)stream);
return ret;
}

static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
{
(void)opaque;
int ret;
ret = ferror((FILE *)stream);
return ret;
Expand Down
9 changes: 4 additions & 5 deletions contrib/minizip/miniunz.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>

#ifdef _WIN32
# include <direct.h>
Expand Down Expand Up @@ -97,7 +98,8 @@ void change_file_date(filename,dosdate,tmu_date)
SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
CloseHandle(hFile);
#else
#ifdef unix || __APPLE__
#if defined(unix) || defined(__APPLE__)
(void)dosdate;
struct utimbuf ut;
struct tm newdate;
newdate.tm_sec = tmu_date.tm_sec;
Expand Down Expand Up @@ -136,7 +138,7 @@ int mymkdir(dirname)
}

int makedir (newdir)
char *newdir;
const char *newdir;
{
char *buffer ;
char *p;
Expand Down Expand Up @@ -324,7 +326,6 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
uInt size_buf;

unz_file_info64 file_info;
uLong ratio=0;
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);

if (err!=UNZ_OK)
Expand Down Expand Up @@ -481,7 +482,6 @@ int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
uLong i;
unz_global_info64 gi;
int err;
FILE* fout=NULL;

err = unzGetGlobalInfo64(uf,&gi);
if (err!=UNZ_OK)
Expand Down Expand Up @@ -515,7 +515,6 @@ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,passwo
int opt_overwrite;
const char* password;
{
int err = UNZ_OK;
if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
{
printf("file %s not found in the zipfile\n",filename);
Expand Down
11 changes: 6 additions & 5 deletions contrib/minizip/minizip.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

#ifdef _WIN32
uLong filetime(f, tmzip, dt)
char *f; /* name of file to get info on */
const char *f; /* name of file to get info on */
tm_zip *tmzip; /* return value: access, modific. and creation times */
uLong *dt; /* dostime */
{
Expand All @@ -94,12 +94,13 @@ uLong filetime(f, tmzip, dt)
return ret;
}
#else
#ifdef unix || __APPLE__
#if defined(unix) || defined(__APPLE__)
uLong filetime(f, tmzip, dt)
char *f; /* name of file to get info on */
const char *f; /* name of file to get info on */
tm_zip *tmzip; /* return value: access, modific. and creation times */
uLong *dt; /* dostime */
{
(void)dt;
int ret=0;
struct stat s; /* results of stat() */
struct tm* filedate;
Expand Down Expand Up @@ -138,7 +139,7 @@ uLong filetime(f, tmzip, dt)
}
#else
uLong filetime(f, tmzip, dt)
char *f; /* name of file to get info on */
const char *f; /* name of file to get info on */
tm_zip *tmzip; /* return value: access, modific. and creation times */
uLong *dt; /* dostime */
{
Expand Down Expand Up @@ -229,7 +230,7 @@ int isLargeFile(const char* filename)

if(pFile != NULL)
{
int n = FSEEKO_FUNC(pFile, 0, SEEK_END);
FSEEKO_FUNC(pFile, 0, SEEK_END);
pos = FTELLO_FUNC(pFile);

printf("File : %s is %lld bytes\n", filename, pos);
Expand Down

0 comments on commit 0530dbc

Please sign in to comment.