Skip to content

Commit

Permalink
Deps: Update to libzip 1.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanTheToaster authored and F0bes committed Dec 6, 2024
1 parent 981fedf commit 58ab271
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 45 deletions.
75 changes: 52 additions & 23 deletions 3rdparty/libzip/lib/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,64 @@ typedef char bool;
#endif
#endif

#ifndef HAVE_FSEEKO
#define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))

#if defined(HAVE__FSEEKI64) && defined(HAVE__FSTAT64) && defined(HAVE__SEEK64)
/* Windows API using int64 */
typedef zip_int64_t zip_off_t;
typedef struct _stat64 zip_os_stat_t;
#define zip_os_stat _stat64
#define zip_os_fstat _fstat64
#define zip_os_seek _fseeki64
#define ZIP_FSEEK_MAX ZIP_INT64_MAX
#define ZIP_FSEEK_MIN ZIP_INT64_MIN
#else

/* Normal API */
#include <sys/stat.h>
typedef struct stat zip_os_stat_t;
#define zip_os_fstat fstat
#define zip_os_stat stat

#if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO)
/* Using off_t */
typedef off_t zip_off_t;
#if SIZEOF_OFF_T == 8
#define ZIP_OFF_MAX ZIP_INT64_MAX
#define ZIP_OFF_MIN ZIP_INT64_MIN
#elif SIZEOF_OFF_T == 4
#define ZIP_OFF_MAX ZIP_INT32_MAX
#define ZIP_OFF_MIN ZIP_INT32_MIN
#elif SIZEOF_OFF_T == 2
#define ZIP_OFF_MAX ZIP_INT16_MAX
#define ZIP_OFF_MIN ZIP_INT16_MIN
#else
#error unsupported size of off_t
#endif

#define ZIP_FSEEK_MAX ZIP_OFF_MAX
#define ZIP_FSEEK_MIN ZIP_OFF_MIN

#define zip_os_fseek fseeko
#define zip_os_ftell ftello
#else

/* Using long */
typedef long zip_off_t;
#include <limits.h>
#define ZIP_FSEEK_MAX LONG_MAX
#define ZIP_FSEEK_MIN LONG_MIN

#define zip_os_fseek fseek
#define zip_os_ftell ftell
#endif

#endif

#ifndef HAVE_FTELLO
#define ftello(s) ((long)ftell((s)))
#endif


#ifdef HAVE_LOCALTIME_S
#ifdef _WIN32
/* Windows is incompatible to the C11 standard, hurray! */
Expand Down Expand Up @@ -179,27 +229,6 @@ typedef char bool;
#endif
#endif

#if SIZEOF_OFF_T == 8
#define ZIP_OFF_MAX ZIP_INT64_MAX
#define ZIP_OFF_MIN ZIP_INT64_MIN
#elif SIZEOF_OFF_T == 4
#define ZIP_OFF_MAX ZIP_INT32_MAX
#define ZIP_OFF_MIN ZIP_INT32_MIN
#elif SIZEOF_OFF_T == 2
#define ZIP_OFF_MAX ZIP_INT16_MAX
#define ZIP_OFF_MIN ZIP_INT16_MIN
#else
#error unsupported size of off_t
#endif

#if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO)
#define ZIP_FSEEK_MAX ZIP_OFF_MAX
#define ZIP_FSEEK_MIN ZIP_OFF_MIN
#else
#include <limits.h>
#define ZIP_FSEEK_MAX LONG_MAX
#define ZIP_FSEEK_MIN LONG_MIN
#endif

#ifndef SIZE_MAX
#if SIZEOF_SIZE_T == 8
Expand Down
11 changes: 10 additions & 1 deletion 3rdparty/libzip/lib/zip_dirent.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <time.h>
#include <zlib.h>

#include "zip.h"
#include "zipint.h"

static zip_string_t *_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str, bool check_consistency);
Expand Down Expand Up @@ -283,6 +282,7 @@ _zip_dirent_init(zip_dirent_t *de) {
de->cloned = 0;

de->crc_valid = true;
de->last_mod_mtime_valid = false;
de->version_madeby = 63 | (ZIP_OPSYS_DEFAULT << 8);
de->version_needed = 10; /* 1.0 */
de->bitflags = 0;
Expand Down Expand Up @@ -1264,3 +1264,12 @@ zip_dirent_check_consistency(zip_dirent_t *dirent) {
}
return 0;
}

time_t zip_dirent_get_last_mod_mtime(zip_dirent_t *de) {
if (!de->last_mod_mtime_valid) {
de->last_mod_mtime = _zip_d2u_time(&de->last_mod);
de->last_mod_mtime_valid = true;
}

return de->last_mod_mtime;
}
20 changes: 15 additions & 5 deletions 3rdparty/libzip/lib/zip_file_set_mtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

#include "zipint.h"

ZIP_EXTERN int
zip_file_set_dostime(zip_t *za, zip_uint64_t idx, zip_uint16_t dtime, zip_uint16_t ddate, zip_flags_t flags) {
static int zip_file_set_time(zip_t *za, zip_uint64_t idx, zip_uint16_t dtime, zip_uint16_t ddate, zip_flags_t flags, time_t *mtime) {
zip_entry_t *e;

if (_zip_get_dirent(za, idx, 0, NULL) == NULL) {
Expand Down Expand Up @@ -66,18 +65,29 @@ zip_file_set_dostime(zip_t *za, zip_uint64_t idx, zip_uint16_t dtime, zip_uint16

e->changes->last_mod.time = dtime;
e->changes->last_mod.date = ddate;
if (mtime != NULL) {
e->changes->last_mod_mtime = *mtime;
e->changes->last_mod_mtime_valid = true;
}
else {
e->changes->last_mod_mtime_valid = false;
}
e->changes->changed |= ZIP_DIRENT_LAST_MOD;

return 0;
}

ZIP_EXTERN int
zip_file_set_mtime(zip_t *za, zip_uint64_t idx, time_t mtime, zip_flags_t flags) {
ZIP_EXTERN int zip_file_set_dostime(zip_t *za, zip_uint64_t idx, zip_uint16_t dtime, zip_uint16_t ddate, zip_flags_t flags) {
return zip_file_set_time(za, idx, dtime, ddate, flags, NULL);
}


ZIP_EXTERN int zip_file_set_mtime(zip_t *za, zip_uint64_t idx, time_t mtime, zip_flags_t flags) {
zip_dostime_t dostime;

if (_zip_u2d_time(mtime, &dostime, &za->error) < 0) {
return -1;
}

return zip_file_set_dostime(za, idx, dostime.time, dostime.date, flags);
return zip_file_set_time(za, idx, dostime.time, dostime.date, flags, &mtime);
}
1 change: 1 addition & 0 deletions 3rdparty/libzip/lib/zip_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ _zip_new(zip_error_t *error) {
za->nopen_source = za->nopen_source_alloc = 0;
za->open_source = NULL;
za->progress = NULL;
za->torrent_mtime = 0;

return za;
}
11 changes: 5 additions & 6 deletions 3rdparty/libzip/lib/zip_source_file_stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

#ifdef _WIN32
#ifndef S_IWUSR
Expand Down Expand Up @@ -120,7 +119,7 @@ _zip_stdio_op_seek(zip_source_file_context_t *ctx, void *f, zip_int64_t offset,
}
#endif

if (fseeko((FILE *)f, (off_t)offset, whence) < 0) {
if (zip_os_fseek((FILE *)f, (zip_off_t)offset, whence) < 0) {
zip_error_set(&ctx->error, ZIP_ER_SEEK, errno);
return false;
}
Expand All @@ -130,15 +129,15 @@ _zip_stdio_op_seek(zip_source_file_context_t *ctx, void *f, zip_int64_t offset,

bool
_zip_stdio_op_stat(zip_source_file_context_t *ctx, zip_source_file_stat_t *st) {
struct stat sb;
zip_os_stat_t sb;

int ret;

if (ctx->fname) {
ret = stat(ctx->fname, &sb);
ret = zip_os_stat(ctx->fname, &sb);
}
else {
ret = fstat(fileno((FILE *)ctx->f), &sb);
ret = zip_os_fstat(fileno((FILE *)ctx->f), &sb);
}

if (ret < 0) {
Expand Down Expand Up @@ -168,7 +167,7 @@ _zip_stdio_op_stat(zip_source_file_context_t *ctx, zip_source_file_stat_t *st) {

zip_int64_t
_zip_stdio_op_tell(zip_source_file_context_t *ctx, void *f) {
off_t offset = ftello((FILE *)f);
zip_off_t offset = zip_os_ftell((FILE *)f);

if (offset < 0) {
zip_error_set(&ctx->error, ZIP_ER_SEEK, errno);
Expand Down
12 changes: 6 additions & 6 deletions 3rdparty/libzip/lib/zip_source_file_stdio_named.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ _zip_stdio_op_create_temp_output_cloning(zip_source_file_context_t *ctx, zip_uin
{
int fd;
struct file_clone_range range;
struct stat st;
zip_os_stat_t st;

if (fstat(fileno(ctx->f), &st) < 0) {
if (zip_os_fstat(fileno(ctx->f), &st) < 0) {
zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
return -1;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ _zip_stdio_op_create_temp_output_cloning(zip_source_file_context_t *ctx, zip_uin
ctx->tmpname = NULL;
return -1;
}
if (fseeko(tfp, (off_t)offset, SEEK_SET) < 0) {
if (zip_os_fseek(tfp, (zip_off_t)offset, SEEK_SET) < 0) {
zip_error_set(&ctx->error, ZIP_ER_TMPOPEN, errno);
(void)fclose(tfp);
(void)remove(ctx->tmpname);
Expand Down Expand Up @@ -290,11 +290,11 @@ _zip_stdio_op_write(zip_source_file_context_t *ctx, const void *data, zip_uint64
static int create_temp_file(zip_source_file_context_t *ctx, bool create_file) {
char *temp;
int mode;
struct stat st;
zip_os_stat_t st;
int fd = 0;
char *start, *end;

if (stat(ctx->fname, &st) == 0) {
if (zip_os_stat(ctx->fname, &st) == 0) {
mode = st.st_mode;
}
else {
Expand Down Expand Up @@ -344,7 +344,7 @@ static int create_temp_file(zip_source_file_context_t *ctx, bool create_file) {
}
}
else {
if (stat(temp, &st) < 0) {
if (zip_os_stat(temp, &st) < 0) {
if (errno == ENOENT) {
break;
}
Expand Down
11 changes: 7 additions & 4 deletions 3rdparty/libzip/lib/zip_stat_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, zip_stat_t *st)
}

if (entry->changes != NULL && entry->changes->changed & ZIP_DIRENT_LAST_MOD) {
st->mtime = _zip_d2u_time(&de->last_mod);
st->mtime = zip_dirent_get_last_mod_mtime(de);
st->valid |= ZIP_STAT_MTIME;
}
}
Expand All @@ -86,7 +86,7 @@ zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, zip_stat_t *st)

st->crc = de->crc;
st->size = de->uncomp_size;
st->mtime = _zip_d2u_time(&de->last_mod);
st->mtime = zip_dirent_get_last_mod_mtime(de);
st->comp_size = de->comp_size;
st->comp_method = (zip_uint16_t)de->comp_method;
st->encryption_method = de->encryption_method;
Expand All @@ -97,9 +97,12 @@ zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, zip_stat_t *st)
}

if ((za->ch_flags & ZIP_AFL_WANT_TORRENTZIP) && (flags & ZIP_FL_UNCHANGED) == 0) {
zip_dostime_t dostime = {0xbc00, 0x2198};
if (za->torrent_mtime == 0) {
zip_dostime_t dostime = {0xbc00, 0x2198};
za->torrent_mtime = _zip_d2u_time(&dostime);
}
st->comp_method = ZIP_CM_DEFLATE;
st->mtime = _zip_d2u_time(&dostime);
st->mtime = za->torrent_mtime;
st->valid |= ZIP_STAT_MTIME | ZIP_STAT_COMP_METHOD;
st->valid &= ~ZIP_STAT_COMP_SIZE;
}
Expand Down
5 changes: 5 additions & 0 deletions 3rdparty/libzip/lib/zipint.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ struct zip {
zip_progress_t *progress; /* progress callback for zip_close() */

zip_uint32_t* write_crc; /* have _zip_write() compute CRC */
time_t torrent_mtime;
};

/* file in zip archive, part of API */
Expand Down Expand Up @@ -346,6 +347,7 @@ struct zip_dirent {
bool cloned; /* whether this instance is cloned, and thus shares non-changed strings */

bool crc_valid; /* if CRC is valid (sometimes not for encrypted archives) */
bool last_mod_mtime_valid;

zip_uint16_t version_madeby; /* (c) version of creator */
zip_uint16_t version_needed; /* (cl) version needed to extract */
Expand All @@ -366,6 +368,8 @@ struct zip_dirent {
zip_uint32_t compression_level; /* level of compression to use (never valid in orig) */
zip_uint16_t encryption_method; /* encryption method, computed from other fields */
char *password; /* file specific encryption password */

time_t last_mod_mtime; /* cached last_mod in Unix time format */
};

/* zip archive central directory */
Expand Down Expand Up @@ -553,6 +557,7 @@ int zip_dirent_check_consistency(zip_dirent_t *dirent);
zip_dirent_t *_zip_dirent_clone(const zip_dirent_t *);
void _zip_dirent_free(zip_dirent_t *);
void _zip_dirent_finalize(zip_dirent_t *);
time_t zip_dirent_get_last_mod_mtime(zip_dirent_t *de);
void _zip_dirent_init(zip_dirent_t *);
bool _zip_dirent_needs_zip64(const zip_dirent_t *, zip_flags_t);
zip_dirent_t *_zip_dirent_new(void);
Expand Down

0 comments on commit 58ab271

Please sign in to comment.