Skip to content

Commit

Permalink
Invoke "64" versions of fseek and fstat on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ktakahashimtb committed Aug 22, 2024
1 parent b10d82b commit add9642
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/zip_source_file_stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,20 @@
#include <sys/stat.h>

#ifdef _WIN32
#define STAT_ST _stat64
#define STAT_F _stat64
#define FSTAT_F _fstat64
#define FSEEK_F _fseeki64
#define OFF_T __int64
#ifndef S_IWUSR
#define S_IWUSR _S_IWRITE
#endif
#else
#define STAT_ST stat
#define STAT_F stat
#define FSTAT_F fstat
#define FSEEK_F fseeko
#define OFF_T off_t
#endif

/* clang-format off */
Expand Down Expand Up @@ -120,7 +131,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 (FSEEK_F((FILE *)f, (OFF_T)offset, whence) < 0) {
zip_error_set(&ctx->error, ZIP_ER_SEEK, errno);
return false;
}
Expand All @@ -130,15 +141,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;
struct STAT_ST sb;

int ret;

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

if (ret < 0) {
Expand Down

0 comments on commit add9642

Please sign in to comment.