diff --git a/docker/mingw64/Dockerfile b/docker/mingw64/Dockerfile index 1e5c423..9cb6dfb 100644 --- a/docker/mingw64/Dockerfile +++ b/docker/mingw64/Dockerfile @@ -1,6 +1,6 @@ # yazc static executable for Windows 64-bits -FROM ubuntu:22.10 +FROM ubuntu:22.04 MAINTAINER Marc Ferland RUN apt update \ diff --git a/lib/file.c b/lib/file.c index ef8e21c..0d6436b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -55,6 +55,41 @@ #define CD_ENTRY64_LEN 56 /* Zip64 central directory entry length */ #define CD_BUF_LEN (MAX_COM_LEN + EOCD_LEN + EOCD64_LOC_LEN) +/* + * Taken from: + * https://opensource.apple.com/source/Libc/Libc-825.25/string/FreeBSD/memmem.c.auto.html + */ +#ifdef __MINGW64__ +void * +memmem(const void *l, size_t l_len, const void *s, size_t s_len) +{ + register char *cur, *last; + const char *cl = (const char *)l; + const char *cs = (const char *)s; + + /* we need something to compare */ + if (l_len == 0 || s_len == 0) + return NULL; + + /* "s" must be smaller or equal to "l" */ + if (l_len < s_len) + return NULL; + + /* special case where s_len == 1 */ + if (s_len == 1) + return memchr(l, (int)*cs, l_len); + + /* the last position where its possible to find "s" in "l" */ + last = (char *)cl + l_len - s_len; + + for (cur = (char *)cl; cur <= last; cur++) + if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0) + return cur; + + return NULL; +} +#endif + /** * SECTION:file * @short_description: libzc zip file @@ -852,7 +887,7 @@ static int read_all_entries_at(struct zc_file *f, off_t cd_offset, uint64_t nben if (!info) goto err; - dbg(f->ctx, "Reading entry: %ld\n", i); + dbg(f->ctx, "Reading entry: %"PRIu64"\n", i); ret = read_single_entry_at(f, cd_offset, &info->header, &info->extra, &cd_offset); @@ -1034,7 +1069,7 @@ static int fill_info_list_central_directory(struct zc_file *f) /* basic sanity checks */ if (!entries_in_cd || cd_offset > sb.st_size) { - err(f->ctx, "detected invalid zip file: entries_in_cd: %ld, cd_offset: 0x%016jx\n", + err(f->ctx, "detected invalid zip file: entries_in_cd: %"PRIu64", cd_offset: 0x%016jx\n", entries_in_cd, cd_offset); to_read = rem; from++; diff --git a/lib/libzc_private.h b/lib/libzc_private.h index 8605af0..2bdd1d3 100644 --- a/lib/libzc_private.h +++ b/lib/libzc_private.h @@ -42,7 +42,13 @@ #define LOG_DEBUG 7 /* debug-level messages */ #endif -static inline void __attribute__((always_inline, format(printf, 2, 3))) +#ifdef __MINGW64__ +#define __ZC_PRINTF_FORMAT __MINGW_PRINTF_FORMAT +#else +#define __ZC_PRINTF_FORMAT printf +#endif + +static inline void __attribute__((always_inline, format(__ZC_PRINTF_FORMAT, 2, 3))) zc_log_null(struct zc_ctx *ctx __attribute__((__unused__)), const char *format __attribute__((__unused__)), ...) { @@ -50,10 +56,10 @@ zc_log_null(struct zc_ctx *ctx __attribute__((__unused__)), void zc_log(struct zc_ctx *ctx, int priority, const char *file, int line, const char *fn, const char *format, ...) - __attribute__((format(printf, 6, 7))); + __attribute__((format(__ZC_PRINTF_FORMAT, 6, 7))); void zc_trace(const char *file, int line, const char *fn, const char *format, - ...) __attribute__((format(printf, 4, 5))); + ...) __attribute__((format(__ZC_PRINTF_FORMAT, 4, 5))); #define zc_log_cond(ctx, prio, arg...) \ do { \ diff --git a/scripts/build-mingw64.sh b/scripts/build-mingw64.sh index a13d008..e4bc942 100755 --- a/scripts/build-mingw64.sh +++ b/scripts/build-mingw64.sh @@ -18,9 +18,9 @@ export PTHREAD_CFLAGS="-I${MINGW_LOCAL_PATH}/include" ../configure --host=x86_64-w64-mingw32 \ --enable-static \ --disable-shared \ - CFLAGS="-Ofast" \ + CPPFLAGS="-D_FILE_OFFSET_BITS=64" \ LDFLAGS="-L${MINGW_LIB_PATH} -lmman ${PTHREAD_LIBS}" -make -j12 +make V=1 V=$(../configure -V | grep 'zc configure' | cut -d' ' -f3) ARCHIVE=yazc-v${V}-win64.zip