#include "../../zutil.h"
#if defined(__linux__)
-# include <sys/auxv.h>
-# include <asm/hwcap.h>
+# include <sys/auxv.h>
+# include <asm/hwcap.h>
#elif defined(_WIN32)
-# include <winapifamily.h>
+# include <winapifamily.h>
#endif
static int arm_has_crc32() {
#if defined(__linux__) && defined(HWCAP2_CRC32)
- return (getauxval(AT_HWCAP2) & HWCAP2_CRC32) != 0 ? 1 : 0;
+ return (getauxval(AT_HWCAP2) & HWCAP2_CRC32) != 0 ? 1 : 0;
#elif defined(ARM_NOCHECK_ACLE)
- return 1;
+ return 1;
#else
- return 0;
+ return 0;
#endif
}
/* AArch64 has neon. */
#if !defined(__aarch64__) && !defined(_M_ARM64)
-static inline int arm_has_neon()
-{
- #if defined(__linux__) && defined(HWCAP_NEON)
+static inline int arm_has_neon() {
+#if defined(__linux__) && defined(HWCAP_NEON)
return (getauxval(AT_HWCAP) & HWCAP_NEON) != 0 ? 1 : 0;
- #elif defined(_M_ARM) && defined(WINAPI_FAMILY_PARTITION)
- #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
+#elif defined(_M_ARM) && defined(WINAPI_FAMILY_PARTITION)
+# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
return 1; /* Always supported */
- #endif
- #endif
+# endif
+#endif
- #if defined(ARM_NOCHECK_NEON)
+#if defined(ARM_NOCHECK_NEON)
return 1;
- #else
+#else
return 0;
- #endif
+#endif
}
#endif
void ZLIB_INTERNAL arm_check_features(void) {
#if defined(__aarch64__) || defined(_M_ARM64)
- arm_cpu_has_neon = 1; /* always available */
+ arm_cpu_has_neon = 1; /* always available */
#else
- arm_cpu_has_neon = arm_has_neon();
+ arm_cpu_has_neon = arm_has_neon();
#endif
- arm_cpu_has_crc32 = arm_has_crc32();
+ arm_cpu_has_crc32 = arm_has_crc32();
}
s->prev[p & s->w_mask] = head;
s->head[hm] = p;
if (p == lp)
- ret = head;
+ ret = head;
} else if (p == lp) {
- ret = p;
+ ret = p;
}
}
return ret;
`posix_memalign' is not an option. Thus, we overallocate and take the
aligned portion of the buffer.
*/
-static inline int is_dfltcc_enabled(void)
-{
+static inline int is_dfltcc_enabled(void) {
uint64_t facilities[(DFLTCC_FACILITY / 64) + 1];
register uint8_t r0 __asm__("r0");
return is_bit_set((const char *)facilities, DFLTCC_FACILITY);
}
-void ZLIB_INTERNAL dfltcc_reset(PREFIX3(streamp) strm, uInt size)
-{
+void ZLIB_INTERNAL dfltcc_reset(PREFIX3(streamp) strm, uInt size) {
struct dfltcc_state *dfltcc_state = (struct dfltcc_state *)((char *)strm->state + ALIGN_UP(size, 8));
struct dfltcc_qaf_param *param = (struct dfltcc_qaf_param *)&dfltcc_state->param;
dfltcc_state->param.ribm = DFLTCC_RIBM;
}
-void ZLIB_INTERNAL *dfltcc_alloc_state(PREFIX3(streamp) strm, uInt items, uInt size)
-{
+void ZLIB_INTERNAL *dfltcc_alloc_state(PREFIX3(streamp) strm, uInt items, uInt size) {
return ZALLOC(strm, ALIGN_UP(items * size, 8) + sizeof(struct dfltcc_state), sizeof(unsigned char));
}
-void ZLIB_INTERNAL dfltcc_copy_state(void *dst, const void *src, uInt size)
-{
+void ZLIB_INTERNAL dfltcc_copy_state(void *dst, const void *src, uInt size) {
memcpy(dst, src, ALIGN_UP(size, 8) + sizeof(struct dfltcc_state));
}
static const int PAGE_ALIGN = 0x1000;
-void ZLIB_INTERNAL *dfltcc_alloc_window(PREFIX3(streamp) strm, uInt items, uInt size)
-{
+void ZLIB_INTERNAL *dfltcc_alloc_window(PREFIX3(streamp) strm, uInt items, uInt size) {
void *p;
void *w;
return w;
}
-void ZLIB_INTERNAL dfltcc_free_window(PREFIX3(streamp) strm, void *w)
-{
+void ZLIB_INTERNAL dfltcc_free_window(PREFIX3(streamp) strm, void *w) {
if (w)
ZFREE(strm, *(void **)((unsigned char *)w - sizeof(void *)));
}
#include "dfltcc_detail.h"
static inline int dfltcc_are_params_ok(int level, uInt window_bits, int strategy, uint16_t level_mask,
- int reproducible)
-{
+ int reproducible) {
return (level_mask & ((uint16_t)1 << level)) != 0 &&
(window_bits == HB_BITS) &&
(strategy == Z_FIXED || strategy == Z_DEFAULT_STRATEGY) &&
}
-int ZLIB_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm)
-{
+int ZLIB_INTERNAL dfltcc_can_deflate(PREFIX3(streamp) strm) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
return 1;
}
-static inline void dfltcc_gdht(PREFIX3(streamp) strm)
-{
+static inline void dfltcc_gdht(PREFIX3(streamp) strm) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param;
size_t avail_in = strm->avail_in;
dfltcc(DFLTCC_GDHT, param, NULL, NULL, &strm->next_in, &avail_in, NULL);
}
-static inline dfltcc_cc dfltcc_cmpr(PREFIX3(streamp) strm)
-{
+static inline dfltcc_cc dfltcc_cmpr(PREFIX3(streamp) strm) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param;
size_t avail_in = strm->avail_in;
return cc;
}
-static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0 *param)
-{
+static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0 *param) {
deflate_state *state = (deflate_state *)strm->state;
send_bits(state, bi_reverse(param->eobs >> (15 - param->eobl), param->eobl), param->eobl, state->bi_buf, state->bi_valid);
#endif
}
-int ZLIB_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state *result)
-{
+int ZLIB_INTERNAL dfltcc_deflate(PREFIX3(streamp) strm, int flush, block_state *result) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 *param = &dfltcc_state->param;
fly with deflateParams, we need to convert between hardware and software
window formats.
*/
-static int dfltcc_was_deflate_used(PREFIX3(streamp) strm)
-{
+static int dfltcc_was_deflate_used(PREFIX3(streamp) strm) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param;
return strm->total_in > 0 || param->nt == 0 || param->hl > 0;
}
-int ZLIB_INTERNAL dfltcc_deflate_params(PREFIX3(streamp) strm, int level, int strategy)
-{
+int ZLIB_INTERNAL dfltcc_deflate_params(PREFIX3(streamp) strm, int level, int strategy) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
int could_deflate = dfltcc_can_deflate(strm);
return Z_STREAM_ERROR;
}
-int ZLIB_INTERNAL dfltcc_can_set_reproducible(PREFIX3(streamp) strm, int reproducible)
-{
+int ZLIB_INTERNAL dfltcc_can_set_reproducible(PREFIX3(streamp) strm, int reproducible) {
deflate_state *state = (deflate_state *)strm->state;
return reproducible != state->reproducible && !dfltcc_was_deflate_used(strm);
/*
Preloading history.
*/
-static void append_history(struct dfltcc_param_v0 *param, unsigned char *history, const unsigned char *buf, uInt count)
-{
+static void append_history(struct dfltcc_param_v0 *param, unsigned char *history, const unsigned char *buf, uInt count) {
size_t offset;
size_t n;
}
int ZLIB_INTERNAL dfltcc_deflate_set_dictionary(PREFIX3(streamp) strm,
- const unsigned char *dictionary, uInt dict_length)
-{
+ const unsigned char *dictionary, uInt dict_length) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 *param = &dfltcc_state->param;
return Z_OK;
}
-int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(PREFIX3(streamp) strm, unsigned char *dictionary, uInt *dict_length)
-{
+int ZLIB_INTERNAL dfltcc_deflate_get_dictionary(PREFIX3(streamp) strm, unsigned char *dictionary, uInt *dict_length) {
deflate_state *state = (deflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 *param = &dfltcc_state->param;
#define DFLTCC_FACILITY 151
static inline dfltcc_cc dfltcc(int fn, void *param,
- unsigned char **op1, size_t *len1, const unsigned char **op2, size_t *len2, void *hist)
-{
+ unsigned char **op1, size_t *len1, const unsigned char **op2, size_t *len2, void *hist) {
unsigned char *t2 = op1 ? *op1 : NULL;
size_t t3 = len1 ? *len1 : 0;
const unsigned char *t4 = op2 ? *op2 : NULL;
static_assert(sizeof(struct dfltcc_qaf_param) == 32, sizeof_struct_dfltcc_qaf_param_is_32);
-static inline int is_bit_set(const char *bits, int n)
-{
+static inline int is_bit_set(const char *bits, int n) {
return bits[n / 8] & (1 << (7 - (n % 8)));
}
-static inline void clear_bit(char *bits, int n)
-{
+static inline void clear_bit(char *bits, int n) {
bits[n / 8] &= ~(1 << (7 - (n % 8)));
}
static_assert(sizeof(struct dfltcc_param_v0) == 1536, sizeof_struct_dfltcc_param_v0_is_1536);
-static inline const char *oesc_msg(char *buf, int oesc)
-{
+static inline const char *oesc_msg(char *buf, int oesc) {
if (oesc == 0x00)
return NULL; /* Successful completion */
else {
#include "dfltcc_inflate.h"
#include "dfltcc_detail.h"
-int ZLIB_INTERNAL dfltcc_can_inflate(PREFIX3(streamp) strm)
-{
+int ZLIB_INTERNAL dfltcc_can_inflate(PREFIX3(streamp) strm) {
struct inflate_state *state = (struct inflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
return is_bit_set(dfltcc_state->af.fns, DFLTCC_XPND) && is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0);
}
-static inline dfltcc_cc dfltcc_xpnd(PREFIX3(streamp) strm)
-{
+static inline dfltcc_cc dfltcc_xpnd(PREFIX3(streamp) strm) {
struct inflate_state *state = (struct inflate_state *)strm->state;
struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param;
size_t avail_in = strm->avail_in;
return cc;
}
-dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(PREFIX3(streamp) strm, int flush, int *ret)
-{
+dfltcc_inflate_action ZLIB_INTERNAL dfltcc_inflate(PREFIX3(streamp) strm, int flush, int *ret) {
struct inflate_state *state = (struct inflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
struct dfltcc_param_v0 *param = &dfltcc_state->param;
DFLTCC_INFLATE_BREAK : DFLTCC_INFLATE_CONTINUE;
}
-int ZLIB_INTERNAL dfltcc_was_inflate_used(PREFIX3(streamp) strm)
-{
+int ZLIB_INTERNAL dfltcc_was_inflate_used(PREFIX3(streamp) strm) {
struct inflate_state *state = (struct inflate_state *)strm->state;
struct dfltcc_param_v0 *param = &GET_DFLTCC_STATE(state)->param;
return !param->nt;
}
-int ZLIB_INTERNAL dfltcc_inflate_disable(PREFIX3(streamp) strm)
-{
+int ZLIB_INTERNAL dfltcc_inflate_disable(PREFIX3(streamp) strm) {
struct inflate_state *state = (struct inflate_state *)strm->state;
struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
/*
- * Compute the CRC32 using a parallelized folding approach with the PCLMULQDQ
+ * Compute the CRC32 using a parallelized folding approach with the PCLMULQDQ
* instruction.
*
* A white paper describing this algorithm can be found at:
"cmp $256 + 16, %[ax]\n\t"
"jb 1b\n\t"
-# if !defined(__x86_64__)
+# if !defined(__x86_64__)
"movzwl -16(%[src0], %[ax]), %[dx]\n\t"
-# else
+# else
"movzwq -16(%[src0], %[ax]), %[dx]\n\t"
-# endif
+# endif
"xorw -16(%[src1], %[ax]), %%dx\n\t"
"jnz 3f\n\t"
/* Concatenate the new bits with the bits currently in the buffer */
unsigned out = s->bi_buf | (value1 << s->bi_valid);
if (width < 32) {
- out |= (value2 << offset2);
- /* Shift out the valid LSBs written out. */
- s->bi_buf = out >> (bytes_out * 8);
- } else /* width => 32 */ {
- unsigned bits_that_fit = 32 - offset2;
- unsigned mask = (1 << bits_that_fit) - 1;
- /* Zero out the high bits of value2 such that the shift by offset2 will
- not cause undefined behavior. */
- out |= ((value2 & mask) << offset2);
+ out |= (value2 << offset2);
+ /* Shift out the valid LSBs written out. */
+ s->bi_buf = out >> (bytes_out * 8);
+ } else { /* width => 32 */
+ unsigned bits_that_fit = 32 - offset2;
+ unsigned mask = (1 << bits_that_fit) - 1;
+ /* Zero out the high bits of value2 such that the shift by offset2 will
+ not cause undefined behavior. */
+ out |= ((value2 & mask) << offset2);
- /* Save in s->bi_buf the bits of value2 that do not fit: they will be
- written in a next full byte. */
- s->bi_buf = (width == 32) ? 0 : value2 >> bits_that_fit;
+ /* Save in s->bi_buf the bits of value2 that do not fit: they will be
+ written in a next full byte. */
+ s->bi_buf = (width == 32) ? 0 : value2 >> bits_that_fit;
}
s->bi_valid = width - (bytes_out * 8);
}
#else
unsigned int count;
- if (UNLIKELY(s->lookahead == 1)){
+ if (UNLIKELY(s->lookahead == 1)) {
count = s->insert - 1;
- }else{
+ } else {
count = s->insert;
}
functable.insert_string(s, str, count);
s->prev[(str+idx) & s->w_mask] = head;
s->head[h & s->hash_mask] = str+idx;
if (idx == count-1)
- ret = head;
+ ret = head;
} else if (idx == count - 1) {
- ret = str + idx;
+ ret = str + idx;
}
}
return ret;
- /* cpu.h -- check for CPU features
- * Copyright (C) 2013 Intel Corporation Jim Kukunas
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
+/* cpu.h -- check for CPU features
+* Copyright (C) 2013 Intel Corporation Jim Kukunas
+* For conditions of distribution and use, see copyright notice in zlib.h
+*/
#ifndef CPU_H_
#define CPU_H_
message(STATUS "Arch detected: '${ARCH}'")
endif()
-
# Base arch detection
if("${ARCH}" MATCHES "(x86_64|AMD64|i[3-6]86)")
set(BASEARCH "x86")
#define ZLIB_INTERNAL
#include "zbuild.h"
#if defined(ZLIB_COMPAT)
-# include "zlib.h"
+# include "zlib.h"
#else
-# include "zlib-ng.h"
+# include "zlib-ng.h"
#endif
/* ===========================================================================
#define DO4 DO1; DO1; DO1; DO1
/* ========================================================================= */
-ZLIB_INTERNAL uint32_t crc32_generic(uint32_t crc, const unsigned char *buf, uint64_t len)
-{
+ZLIB_INTERNAL uint32_t crc32_generic(uint32_t crc, const unsigned char *buf, uint64_t len) {
crc = crc ^ 0xffffffff;
#ifdef UNROLL_MORE
}
/* ========================================================================= */
-static void crc32_combine_gen_(uint32_t *op, z_off64_t len2)
-{
+
+static void crc32_combine_gen_(uint32_t *op, z_off64_t len2) {
uint32_t row;
int j;
unsigned i;
}
/* ========================================================================= */
-void ZEXPORT PREFIX(crc32_combine_gen)(uint32_t *op, z_off_t len2)
-{
+
+void ZEXPORT PREFIX(crc32_combine_gen)(uint32_t *op, z_off_t len2) {
crc32_combine_gen_(op, len2);
}
-void ZEXPORT PREFIX(crc32_combine_gen64)(uint32_t *op, z_off64_t len2)
-{
+void ZEXPORT PREFIX(crc32_combine_gen64)(uint32_t *op, z_off64_t len2) {
crc32_combine_gen_(op, len2);
}
/* ========================================================================= */
-uint32_t ZEXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t *op)
-{
+uint32_t ZEXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t *op) {
return gf2_matrix_times(op, crc1) ^ crc2;
}
n = s->hash_size;
p = &s->head[n];
#ifdef NOT_TWEAK_COMPILER
- do {
- unsigned m;
- m = *--p;
- *p = (Pos)(m >= wsize ? m-wsize : NIL);
- } while (--n);
+ do {
+ unsigned m;
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ } while (--n);
#else
- /* As of I make this change, gcc (4.8.*) isn't able to vectorize
- * this hot loop using saturated-subtraction on x86-64 architecture.
- * To avoid this defect, we can change the loop such that
- * o. the pointer advance forward, and
- * o. demote the variable 'm' to be local to the loop, and
- * choose type "Pos" (instead of 'unsigned int') for the
- * variable to avoid unncessary zero-extension.
- */
- {
- unsigned int i;
- Pos *q = p - n;
- for (i = 0; i < n; i++) {
- Pos m = *q;
- Pos t = wsize;
- *q++ = (Pos)(m >= t ? m-t: NIL);
- }
- }
+ /* As of I make this change, gcc (4.8.*) isn't able to vectorize
+ * this hot loop using saturated-subtraction on x86-64 architecture.
+ * To avoid this defect, we can change the loop such that
+ * o. the pointer advance forward, and
+ * o. demote the variable 'm' to be local to the loop, and
+ * choose type "Pos" (instead of 'unsigned int') for the
+ * variable to avoid unncessary zero-extension.
+ */
+ {
+ unsigned int i;
+ Pos *q = p - n;
+ for (i = 0; i < n; i++) {
+ Pos m = *q;
+ Pos t = wsize;
+ *q++ = (Pos)(m >= t ? m-t: NIL);
+ }
+ }
#endif /* NOT_TWEAK_COMPILER */
- n = wsize;
- p = &s->prev[n];
+ n = wsize;
+ p = &s->prev[n];
#ifdef NOT_TWEAK_COMPILER
- do {
- unsigned m;
- m = *--p;
- *p = (Pos)(m >= wsize ? m-wsize : NIL);
- /* If n is not on any hash chain, prev[n] is garbage but
- * its value will never be used.
- */
- } while (--n);
+ do {
+ unsigned m;
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ /* If n is not on any hash chain, prev[n] is garbage but
+ * its value will never be used.
+ */
+ } while (--n);
#else
- {
- unsigned int i;
- Pos *q = p - n;
- for (i = 0; i < n; i++) {
- Pos m = *q;
- Pos t = wsize;
- *q++ = (Pos)(m >= t ? m-t: NIL);
- }
- }
+ {
+ unsigned int i;
+ Pos *q = p - n;
+ for (i = 0; i < n; i++) {
+ Pos m = *q;
+ Pos t = wsize;
+ *q++ = (Pos)(m >= t ? m-t: NIL);
+ }
+ }
#endif /* NOT_TWEAK_COMPILER */
}
}
/* ========================================================================= */
-int ZEXPORT PREFIX(deflateGetDictionary)(PREFIX3(stream) *strm, unsigned char *dictionary, unsigned int *dictLength) {
+int ZEXPORT PREFIX(deflateGetDictionary)(PREFIX3(stream) *strm, unsigned char *dictionary, unsigned int *dictLength) {
deflate_state *s;
unsigned int len;
return Z_OK;
}
- /* Make sure there is something to do and avoid duplicate consecutive
- * flushes. For repeated and useless calls with Z_FINISH, we keep
- * returning Z_STREAM_END instead of Z_BUF_ERROR.
- */
+ /* Make sure there is something to do and avoid duplicate consecutive
+ * flushes. For repeated and useless calls with Z_FINISH, we keep
+ * returning Z_STREAM_END instead of Z_BUF_ERROR.
+ */
} else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
flush != Z_FINISH) {
ERR_RETURN(strm, Z_BUF_ERROR);
s->last_flush = -1;
return Z_OK;
}
- }
- else {
+ } else {
put_byte(s, (s->gzhead->text ? 1 : 0) +
(s->gzhead->hcrc ? 2 : 0) +
(s->gzhead->extra == NULL ? 0 : 4) +
}
flush_pending(strm);
if (strm->avail_out == 0) {
- s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
- return Z_OK;
+ s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
+ return Z_OK;
}
}
}
}
#else
unsigned int count;
- if (UNLIKELY(s->lookahead == 1)){
+ if (UNLIKELY(s->lookahead == 1)) {
count = s->insert - 1;
- }else{
+ } else {
count = s->insert;
}
functable.insert_string(s,str,count);
memcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
s->strstart = s->w_size;
s->insert = s->strstart;
- }
- else {
+ } else {
if (s->window_size - s->strstart <= used) {
/* Slide the window down. */
s->strstart -= s->w_size;
unsigned int hash_bits; /* log2(hash_size) */
unsigned int hash_mask; /* hash_size-1 */
- #if !defined(__x86_64__) && !defined(_M_X64) && !defined(__i386) && !defined(_M_IX86)
+#if !defined(__x86_64__) && !defined(_M_X64) && !defined(__i386) && !defined(_M_IX86)
unsigned int hash_shift;
- #endif
+#endif
/* Number of bits by which ins_h must be shifted at each input
* step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is:
/* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf.
*/
-#define put_byte(s, c) {s->pending_buf[s->pending++] = (unsigned char)(c);}
+#define put_byte(s, c) { \
+ s->pending_buf[s->pending++] = (unsigned char)(c); \
+}
/* ===========================================================================
* Output a short LSB first on the stream.
*/
static inline void put_short(deflate_state *s, uint16_t w) {
#if BYTE_ORDER == BIG_ENDIAN
- w = ZSWAP16(w);
+ w = ZSWAP16(w);
#endif
- memcpy(&(s->pending_buf[s->pending]), &w, sizeof(uint16_t));
- s->pending += 2;
+ memcpy(&(s->pending_buf[s->pending]), &w, sizeof(uint16_t));
+ s->pending += 2;
}
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
#ifndef ZLIB_DEBUG
/* Inline versions of _tr_tally for speed: */
- extern const unsigned char ZLIB_INTERNAL zng_length_code[];
- extern const unsigned char ZLIB_INTERNAL zng_dist_code[];
+extern const unsigned char ZLIB_INTERNAL zng_length_code[];
+extern const unsigned char ZLIB_INTERNAL zng_dist_code[];
-# define zng_tr_tally_lit(s, c, flush) \
+# define zng_tr_tally_lit(s, c, flush) \
{ unsigned char cc = (c); \
s->sym_buf[s->sym_next++] = 0; \
s->sym_buf[s->sym_next++] = 0; \
s->dyn_ltree[cc].Freq++; \
flush = (s->sym_next == s->sym_end); \
}
-# define zng_tr_tally_dist(s, distance, length, flush) \
+# define zng_tr_tally_dist(s, distance, length, flush) \
{ unsigned char len = (unsigned char)(length); \
unsigned dist = (unsigned)(distance); \
s->sym_buf[s->sym_next++] = dist; \
flush = (s->sym_next == s->sym_end); \
}
#else
-# define zng_tr_tally_lit(s, c, flush) flush = zng_tr_tally(s, 0, c)
-# define zng_tr_tally_dist(s, distance, length, flush) \
+# define zng_tr_tally_lit(s, c, flush) flush = zng_tr_tally(s, 0, c)
+# define zng_tr_tally_dist(s, distance, length, flush) \
flush = zng_tr_tally(s, (unsigned)(distance), (unsigned)(length))
#endif
*/
#ifdef NOT_TWEAK_COMPILER
-#define TRIGGER_LEVEL 6
+# define TRIGGER_LEVEL 6
#else
-#define TRIGGER_LEVEL 5
+# define TRIGGER_LEVEL 5
#endif
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
-#define UPDATE_HASH(s, h, i) \
+# define UPDATE_HASH(s, h, i) \
do {\
if (s->level < TRIGGER_LEVEL) \
h = (3483 * (s->window[i]) +\
25811* (s->window[i+2])) & s->hash_mask;\
} while (0)
#else
-# define UPDATE_HASH(s, h, i) (h = (((h) << s->hash_shift) ^ (s->window[i + (MIN_MATCH-1)])) & s->hash_mask)
+# define UPDATE_HASH(s, h, i) \
+ (h = (((h) << s->hash_shift) ^ (s->window[i + (MIN_MATCH-1)])) & s->hash_mask)
#endif
#ifdef ZLIB_DEBUG
- #define send_code(s, c, tree, bit_buf, bits_valid) { \
+# define send_code(s, c, tree, bit_buf, bits_valid) { \
if (z_verbose > 2) { \
fprintf(stderr, "\ncd %3d ", (c)); \
} \
send_bits(s, tree[c].Code, tree[c].Len, bit_buf, bits_valid); \
}
#else /* ZLIB_DEBUG */
- /* Send a code of the given tree. c and tree must not have side effects */
- #define send_code(s, c, tree, bit_buf, bits_valid) send_bits(s, tree[c].Code, tree[c].Len, bit_buf, bits_valid)
+/* Send a code of the given tree. c and tree must not have side effects */
+# define send_code(s, c, tree, bit_buf, bits_valid) \
+ send_bits(s, tree[c].Code, tree[c].Len, bit_buf, bits_valid)
#endif
#ifdef ZLIB_DEBUG
- #define send_debug_trace(s, value, length) {\
+# define send_debug_trace(s, value, length) {\
Tracevv((stderr, " l %2d v %4x ", length, value));\
Assert(length > 0 && length <= 15, "invalid length");\
s->bits_sent += (unsigned long)length;\
}
#else
- #define send_debug_trace(s, value, length) {}
+# define send_debug_trace(s, value, length) {}
#endif
/* If not enough room in bit_buf, use (valid) bits from bit_buf and
#warning Call insert_string() MIN_MATCH-3 more times
#endif
#endif
- /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
- * matter since it will be recomputed at next deflate call.
- */
+ /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
+ * matter since it will be recomputed at next deflate call.
+ */
}
}
Pos head = s->head[s->ins_h];
if (head != str+idx) {
- s->prev[(str+idx) & s->w_mask] = head;
- s->head[s->ins_h] = str+idx;
- if (idx == count - 1)
- ret = head;
+ s->prev[(str+idx) & s->w_mask] = head;
+ s->head[s->ins_h] = str+idx;
+ if (idx == count - 1)
+ ret = head;
} else if (idx == count - 1) {
- ret = str + idx;
+ ret = str + idx;
}
}
return ret;
#include <intrin.h>
#ifdef X86_CPUID
-# include "arch/x86/x86.h"
+# include "arch/x86/x86.h"
#endif
#if defined(_MSC_VER) && !defined(__clang__)
/* This is not a general purpose replacement for __builtin_ctzl. The function expects that value is != 0
* Because of that assumption trailing_zero is not initialized and the return value of _BitScanForward is not checked
*/
-static __forceinline unsigned long __builtin_ctzl(unsigned long value)
-{
+static __forceinline unsigned long __builtin_ctzl(unsigned long value) {
#ifdef X86_CPUID
if (x86_cpu_has_tzcnt)
return _tzcnt_u32(value);
/* functable init */
ZLIB_INTERNAL __thread struct functable_s functable = {
- fill_window_stub,
- insert_string_stub,
- adler32_stub,
- crc32_stub,
- slide_hash_stub
- };
+ fill_window_stub,
+ insert_string_stub,
+ adler32_stub,
+ crc32_stub,
+ slide_hash_stub
+};
/* stub functions */
ZLIB_INTERNAL Pos insert_string_stub(deflate_state *const s, const Pos str, unsigned int count) {
// Initialize default
- functable.insert_string=&insert_string_c;
+ functable.insert_string = &insert_string_c;
- #ifdef X86_SSE42_CRC_HASH
+#ifdef X86_SSE42_CRC_HASH
if (x86_cpu_has_sse42)
- functable.insert_string=&insert_string_sse;
- #elif defined(__ARM_FEATURE_CRC32) && defined(ARM_ACLE_CRC_HASH)
+ functable.insert_string = &insert_string_sse;
+#elif defined(__ARM_FEATURE_CRC32) && defined(ARM_ACLE_CRC_HASH)
if (arm_cpu_has_crc32)
- functable.insert_string=&insert_string_acle;
- #endif
+ functable.insert_string = &insert_string_acle;
+#endif
return functable.insert_string(s, str, count);
}
ZLIB_INTERNAL void fill_window_stub(deflate_state *s) {
// Initialize default
- functable.fill_window=&fill_window_c;
+ functable.fill_window = &fill_window_c;
- #if defined(X86_SSE2)
- # if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2)
+#if defined(X86_SSE2)
+# if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2)
if (x86_cpu_has_sse2)
- # endif
- functable.fill_window=&fill_window_sse;
- #elif defined(ARM_GETAUXVAL)
- functable.fill_window=&fill_window_arm;
- #endif
+# endif
+ functable.fill_window = &fill_window_sse;
+#elif defined(ARM_GETAUXVAL)
+ functable.fill_window = &fill_window_arm;
+#endif
functable.fill_window(s);
}
ZLIB_INTERNAL void slide_hash_stub(deflate_state *s) {
// Initialize default
- functable.slide_hash=&slide_hash_c;
+ functable.slide_hash = &slide_hash_c;
- #ifdef X86_SSE2
- # if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2)
+#ifdef X86_SSE2
+# if !defined(__x86_64__) && !defined(_M_X64) && !defined(X86_NOCHECK_SSE2)
if (x86_cpu_has_sse2)
- # endif
- functable.slide_hash=&slide_hash_sse2;
- #endif
+# endif
+ functable.slide_hash = &slide_hash_sse2;
+#endif
functable.slide_hash(s);
}
ZLIB_INTERNAL uint32_t adler32_stub(uint32_t adler, const unsigned char *buf, size_t len) {
// Initialize default
- functable.adler32=&adler32_c;
+ functable.adler32 = &adler32_c;
- #if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && defined(ARM_NEON_ADLER32)
+#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && defined(ARM_NEON_ADLER32)
if (arm_cpu_has_neon)
- functable.adler32=&adler32_neon;
- #endif
+ functable.adler32 = &adler32_neon;
+#endif
return functable.adler32(adler, buf, len);
}
ZLIB_INTERNAL uint32_t crc32_stub(uint32_t crc, const unsigned char *buf, uint64_t len) {
-
- Assert(sizeof(uint64_t) >= sizeof(size_t),
- "crc32_z takes size_t but internally we have a uint64_t len");
-/* return a function pointer for optimized arches here after a capability test */
+ Assert(sizeof(uint64_t) >= sizeof(size_t),
+ "crc32_z takes size_t but internally we have a uint64_t len");
+ /* return a function pointer for optimized arches here after a capability test */
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
if (sizeof(void *) == sizeof(ptrdiff_t)) {
#if BYTE_ORDER == LITTLE_ENDIAN
- functable.crc32=crc32_little;
+ functable.crc32 = crc32_little;
# if defined(__ARM_FEATURE_CRC32) && defined(ARM_ACLE_CRC_HASH)
- if (arm_cpu_has_crc32)
- functable.crc32=crc32_acle;
+ if (arm_cpu_has_crc32)
+ functable.crc32 = crc32_acle;
# endif
#elif BYTE_ORDER == BIG_ENDIAN
- functable.crc32=crc32_big;
+ functable.crc32 = crc32_big;
#else
# error No endian defined
#endif
} else {
- functable.crc32=crc32_generic;
+ functable.crc32 = crc32_generic;
}
return functable.crc32(crc, buf, len);
#include <fcntl.h>
#if defined(ZLIB_COMPAT)
-# include "zlib.h"
+# include "zlib.h"
#else
-# include "zlib-ng.h"
+# include "zlib-ng.h"
#endif
#ifdef WIN32
/* default i/o buffer size -- double this for output when reading (this and
twice this must be able to fit in an unsigned type) */
#if defined(S390_DFLTCC_DEFLATE) || defined(S390_DFLTCC_INFLATE)
-#define GZBUFSIZE 262144 /* DFLTCC works faster with larger buffers */
+# define GZBUFSIZE 262144 /* DFLTCC works faster with larger buffers */
#else
-#define GZBUFSIZE 8192
+# define GZBUFSIZE 8192
#endif
/* gzip modes, also provide a little integrity check on the passed structure */
the contents, let the user worry about that) */
str = buf;
left = (unsigned)len - 1;
- if (left) do {
- /* assure that something is in the output buffer */
- if (state->x.have == 0 && gz_fetch(state) == -1)
- return NULL; /* error */
- if (state->x.have == 0) { /* end of file */
- state->past = 1; /* read past end */
- break; /* return what we have */
- }
-
- /* look for end-of-line in current output buffer */
- n = state->x.have > left ? left : state->x.have;
- eol = (unsigned char *)memchr(state->x.next, '\n', n);
- if (eol != NULL)
- n = (unsigned)(eol - state->x.next) + 1;
-
- /* copy through end-of-line, or remainder if not found */
- memcpy(buf, state->x.next, n);
- state->x.have -= n;
- state->x.next += n;
- state->x.pos += n;
- left -= n;
- buf += n;
- } while (left && eol == NULL);
+ if (left) {
+ do {
+ /* assure that something is in the output buffer */
+ if (state->x.have == 0 && gz_fetch(state) == -1)
+ return NULL; /* error */
+ if (state->x.have == 0) { /* end of file */
+ state->past = 1; /* read past end */
+ break; /* return what we have */
+ }
+
+ /* look for end-of-line in current output buffer */
+ n = state->x.have > left ? left : state->x.have;
+ eol = (unsigned char *)memchr(state->x.next, '\n', n);
+ if (eol != NULL)
+ n = (unsigned)(eol - state->x.next) + 1;
+
+ /* copy through end-of-line, or remainder if not found */
+ memcpy(buf, state->x.next, n);
+ state->x.have -= n;
+ state->x.next += n;
+ state->x.pos += n;
+ left -= n;
+ buf += n;
+ } while (left && eol == NULL);
+ }
/* return terminated string, or if nothing, end of file */
if (buf == str)
in() should return zero on failure. out() should return non-zero on
failure. If either in() or out() fails, than inflateBack() returns a
Z_BUF_ERROR. strm->next_in can be checked for NULL to see whether it
- was in() or out() that caused in the error. Otherwise, inflateBack()
+ was in() or out() that caused in the error. Otherwise, inflateBack()
returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
error, or Z_MEM_ERROR if it could not allocate memory for the state.
inflateBack() can also return Z_STREAM_ERROR if the input parameters
out = chunkmemset(out, dist, len);
#else
if (len < sizeof(uint64_t))
- out = set_bytes(out, out - dist, dist, len);
+ out = set_bytes(out, out - dist, dist, len);
else if (dist == 1)
- out = byte_memset(out, len);
+ out = byte_memset(out, len);
else
- out = chunk_memset(out, out - dist, dist, len);
+ out = chunk_memset(out, out - dist, dist, len);
#endif
}
} else if ((op & 64) == 0) { /* 2nd level distance code */
state->distbits = 5;
}
-int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state)
-{
+int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state) {
/* if it hasn't been done already, allocate space for the window */
if (state->window == NULL) {
#ifdef INFFAST_CHUNKSIZE
longest code or if it is less than the shortest code.
*/
int ZLIB_INTERNAL zng_inflate_table(codetype type, uint16_t *lens, unsigned codes,
- code * *table, unsigned *bits, uint16_t *work) {
+ code * *table, unsigned *bits, uint16_t *work) {
unsigned len; /* a code's length in bits */
unsigned sym; /* index of code symbols */
unsigned min, max; /* minimum and maximum code lengths */
#if defined(_MSC_VER) && !defined(__clang__)
-# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined(_M_ARM) || defined(_M_ARM64)
-# include "fallback_builtins.h"
-# endif
+# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined(_M_ARM) || defined(_M_ARM64)
+# include "fallback_builtins.h"
+# endif
#endif
Assert((unsigned long)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead");
do {
if (cur_match >= s->strstart) {
- break;
+ break;
}
match = s->window + cur_match;
do {
unsigned char *match;
if (cur_match >= s->strstart) {
- break;
+ break;
}
match = s->window + cur_match;
memcpy(&mval, match, sizeof(mval));
memcpy(&sval, scan, sizeof(sval));
if (mval != sval)
- break;
+ break;
match += sizeof(mval);
scan += sizeof(sval);
memcpy(&mval, match, sizeof(mval));
memcpy(&sval, scan, sizeof(sval));
if (mval != sval)
- break;
+ break;
match += sizeof(mval);
scan += sizeof(sval);
memcpy(&mval, match, sizeof(mval));
memcpy(&sval, scan, sizeof(sval));
if (mval != sval)
- break;
+ break;
match += sizeof(mval);
scan += sizeof(sval);
memcpy(&mval, match, sizeof(mval));
memcpy(&sval, scan, sizeof(sval));
if (mval != sval)
- break;
+ break;
match += sizeof(mval);
scan += sizeof(sval);
} while (scan < strend);
do {
if (cur_match >= strstart) {
- break;
+ break;
}
/* Skip to next match if the match length cannot increase
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#ifndef MEMCOPY_H_
- #define MEMCOPY_H_
+#define MEMCOPY_H_
- #include "zendian.h"
+#include "zendian.h"
/* Load 64 bits from IN and place the bytes at offset BITS in the result. */
static inline uint64_t load_64_bits(const unsigned char *in, unsigned bits) {
- uint64_t chunk;
- memcpy(&chunk, in, sizeof(chunk));
-
- #if BYTE_ORDER == LITTLE_ENDIAN
- return chunk << bits;
- #else
- return ZSWAP64(chunk) << bits;
- #endif
+ uint64_t chunk;
+ memcpy(&chunk, in, sizeof(chunk));
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ return chunk << bits;
+#else
+ return ZSWAP64(chunk) << bits;
+#endif
}
- #if defined(__ARM_NEON__) || defined(__ARM_NEON)
- #include <arm_neon.h>
+#if defined(__ARM_NEON__) || defined(__ARM_NEON)
+#include <arm_neon.h>
typedef uint8x16_t inffast_chunk_t;
- #define INFFAST_CHUNKSIZE sizeof(inffast_chunk_t)
- #endif
+#define INFFAST_CHUNKSIZE sizeof(inffast_chunk_t)
+#endif
- #if defined(X86_SSE2)
- #include <immintrin.h>
+#if defined(X86_SSE2)
+#include <immintrin.h>
typedef __m128i inffast_chunk_t;
- #define INFFAST_CHUNKSIZE sizeof(inffast_chunk_t)
- #endif
+#define INFFAST_CHUNKSIZE sizeof(inffast_chunk_t)
+#endif
- #ifdef INFFAST_CHUNKSIZE
+#ifdef INFFAST_CHUNKSIZE
/*
Ask the compiler to perform a wide, unaligned load with an machine
instruction appropriate for the inffast_chunk_t type.
}
static inline inffast_chunk_t chunkmemset_1(unsigned char *from) {
- #if defined(X86_SSE2)
+#if defined(X86_SSE2)
int8_t c;
memcpy(&c, from, sizeof(c));
return _mm_set1_epi8(c);
- #elif defined(__ARM_NEON__) || defined(__ARM_NEON)
+#elif defined(__ARM_NEON__) || defined(__ARM_NEON)
return vld1q_dup_u8(from);
- #endif
+#endif
}
static inline inffast_chunk_t chunkmemset_2(unsigned char *from) {
int16_t c;
memcpy(&c, from, sizeof(c));
- #if defined(X86_SSE2)
+#if defined(X86_SSE2)
return _mm_set1_epi16(c);
- #elif defined(__ARM_NEON__) || defined(__ARM_NEON)
+#elif defined(__ARM_NEON__) || defined(__ARM_NEON)
return vreinterpretq_u8_s16(vdupq_n_s16(c));
- #endif
+#endif
}
static inline inffast_chunk_t chunkmemset_4(unsigned char *from) {
int32_t c;
memcpy(&c, from, sizeof(c));
- #if defined(X86_SSE2)
+#if defined(X86_SSE2)
return _mm_set1_epi32(c);
- #elif defined(__ARM_NEON__) || defined(__ARM_NEON)
+#elif defined(__ARM_NEON__) || defined(__ARM_NEON)
return vreinterpretq_u8_s32(vdupq_n_s32(c));
- #endif
+#endif
}
static inline inffast_chunk_t chunkmemset_8(unsigned char *from) {
- #if defined(X86_SSE2)
+#if defined(X86_SSE2)
int64_t c;
memcpy(&c, from, sizeof(c));
return _mm_set1_epi64x(c);
- #elif defined(__ARM_NEON__) || defined(__ARM_NEON)
+#elif defined(__ARM_NEON__) || defined(__ARM_NEON)
return vcombine_u8(vld1_u8(from), vld1_u8(from));
- #endif
+#endif
}
- #if defined(__ARM_NEON__) || defined(__ARM_NEON)
+#if defined(__ARM_NEON__) || defined(__ARM_NEON)
static inline unsigned char *chunkmemset_3(unsigned char *out, unsigned char *from, unsigned dist, unsigned len) {
uint8x8x3_t chunks;
unsigned sz = sizeof(chunks);
out = chunkunroll(out, &dist, &rem);
return chunkcopy(out, out - dist, rem);
}
- #endif
+#endif
- #if defined(__aarch64__) || defined(_M_ARM64)
+#if defined(__aarch64__) || defined(_M_ARM64)
static inline unsigned char *chunkmemset_6(unsigned char *out, unsigned char *from, unsigned dist, unsigned len) {
uint16x8x3_t chunks;
unsigned sz = sizeof(chunks);
out = chunkunroll(out, &dist, &rem);
return chunkcopy(out, out - dist, rem);
}
- #endif
+#endif
/* Copy DIST bytes from OUT - DIST into OUT + DIST * k, for 0 <= k < LEN/DIST. Return OUT + LEN. */
static inline unsigned char *chunkmemset(unsigned char *out, unsigned dist, unsigned len) {
- /* Debug performance related issues when len < sizeof(uint64_t):
+ /* Debug performance related issues when len < sizeof(uint64_t):
Assert(len >= sizeof(uint64_t), "chunkmemset should be called on larger chunks"); */
Assert(dist > 0, "cannot have a distance 0");
chunk = chunkmemset_2(from);
break;
}
- #if defined(__ARM_NEON__) || defined(__ARM_NEON)
+#if defined(__ARM_NEON__) || defined(__ARM_NEON)
case 3:
- return chunkmemset_3(out, from, dist, len);
- #endif
+ return chunkmemset_3(out, from, dist, len);
+#endif
case 4: {
chunk = chunkmemset_4(from);
break;
}
- #if defined(__aarch64__) || defined(_M_ARM64)
+#if defined(__aarch64__) || defined(_M_ARM64)
case 6:
return chunkmemset_6(out, from, dist, len);
- #endif
+#endif
case 8: {
chunk = chunkmemset_8(from);
break;
static inline unsigned char* chunkmemsetsafe(unsigned char *out, unsigned dist, unsigned len, unsigned left) {
if (left < (unsigned)(3 * INFFAST_CHUNKSIZE)) {
while (len > 0) {
- *out = *(out - dist);
- out++;
- --len;
+ *out = *(out - dist);
+ out++;
+ --len;
}
return out;
}
return chunkmemset(out, dist, len);
}
- #else /* INFFAST_CHUNKSIZE */
+#else /* INFFAST_CHUNKSIZE */
static inline unsigned char *copy_1_bytes(unsigned char *out, unsigned char *from) {
*out++ = *from;
static inline unsigned char *copy_bytes(unsigned char *out, unsigned char *from, unsigned len) {
Assert(len < 8, "copy_bytes should be called with less than 8 bytes");
- #ifndef UNALIGNED_OK
+#ifndef UNALIGNED_OK
while (len--) {
*out++ = *from++;
}
return out;
- #else
+#else
switch (len) {
case 7:
return copy_7_bytes(out, from);
}
return out;
- #endif /* UNALIGNED_OK */
+#endif /* UNALIGNED_OK */
}
/* Copy LEN bytes (7 or fewer) from FROM into OUT. Return OUT + LEN. */
static inline unsigned char *set_bytes(unsigned char *out, unsigned char *from, unsigned dist, unsigned len) {
Assert(len < 8, "set_bytes should be called with less than 8 bytes");
- #ifndef UNALIGNED_OK
+#ifndef UNALIGNED_OK
(void)dist;
while (len--) {
*out++ = *from++;
}
return out;
- #else
+#else
if (dist >= len)
return copy_bytes(out, from, len);
}
}
return out;
- #endif /* UNALIGNED_OK */
+#endif /* UNALIGNED_OK */
}
/* Byte by byte semantics: copy LEN bytes from OUT + DIST and write them to OUT. Return OUT + LEN. */
return chunk_memcpy(out, from, len);
}
- #endif /* INFFAST_CHUNKSIZE */
+#endif /* INFFAST_CHUNKSIZE */
#endif /* MEMCOPY_H_ */
/* ===========================================================================
* Test compress() and uncompress()
*/
-void test_compress(unsigned char *compr, z_size_t comprLen, unsigned char *uncompr, z_size_t uncomprLen)
-{
+void test_compress(unsigned char *compr, z_size_t comprLen, unsigned char *uncompr, z_size_t uncomprLen) {
int err;
size_t len = strlen(hello)+1;
/* ===========================================================================
* Test read/write of .gz files
*/
-void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen)
-{
+void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) {
#ifdef NO_GZCOMPRESS
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
#else
/* ===========================================================================
* Test deflate() with small buffers
*/
-void test_deflate(unsigned char *compr, size_t comprLen)
-{
+void test_deflate(unsigned char *compr, size_t comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
size_t len = strlen(hello)+1;
/* ===========================================================================
* Test inflate() with small buffers
*/
-void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen)
-{
+void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
int err;
PREFIX3(stream) d_stream; /* decompression stream */
/* ===========================================================================
* Test deflate() with large buffers and dynamic change of compression level
*/
-void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen, int zng_params)
-{
+void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen, int zng_params) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
#ifndef ZLIB_COMPAT
/* ===========================================================================
* Test inflate() with large buffers
*/
-void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen)
-{
+void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
int err;
PREFIX3(stream) d_stream; /* decompression stream */
/* ===========================================================================
* Test deflate() with full flush
*/
-void test_flush(unsigned char *compr, z_size_t *comprLen)
-{
+void test_flush(unsigned char *compr, z_size_t *comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
unsigned int len = (unsigned int)strlen(hello)+1;
/* ===========================================================================
* Test inflateSync()
*/
-void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen)
-{
+void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
int err;
PREFIX3(stream) d_stream; /* decompression stream */
/* ===========================================================================
* Test deflate() with preset dictionary
*/
-void test_dict_deflate(unsigned char *compr, size_t comprLen)
-{
+void test_dict_deflate(unsigned char *compr, size_t comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
/* ===========================================================================
* Test inflate() with a preset dictionary
*/
-void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen)
-{
+void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
int err;
PREFIX3(stream) d_stream; /* decompression stream */
/* ===========================================================================
* Test deflateBound() with small buffers
*/
-void test_deflate_bound(void)
-{
+void test_deflate_bound(void) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
unsigned int len = (unsigned int)strlen(hello)+1;
/* ===========================================================================
* Test deflateCopy() with small buffers
*/
-void test_deflate_copy(unsigned char *compr, size_t comprLen)
-{
+void test_deflate_copy(unsigned char *compr, size_t comprLen) {
PREFIX3(stream) c_stream, c_stream_copy; /* compression stream */
int err;
size_t len = strlen(hello)+1;
/* ===========================================================================
* Test deflateGetDictionary() with small buffers
*/
-void test_deflate_get_dict(unsigned char *compr, size_t comprLen)
-{
+void test_deflate_get_dict(unsigned char *compr, size_t comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
unsigned char *dictNew = NULL;
/* ===========================================================================
* Test deflatePending() with small buffers
*/
-void test_deflate_pending(unsigned char *compr, size_t comprLen)
-{
+void test_deflate_pending(unsigned char *compr, size_t comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
int *bits = calloc(256, 1);
/* ===========================================================================
* Test deflatePrime() with small buffers
*/
-void test_deflate_prime(unsigned char *compr, size_t comprLen)
-{
+void test_deflate_prime(unsigned char *compr, size_t comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
int bits = 0;
/* ===========================================================================
* Test deflateSetHeader() with small buffers
*/
-void test_deflate_set_header(unsigned char *compr, size_t comprLen)
-{
+void test_deflate_set_header(unsigned char *compr, size_t comprLen) {
PREFIX(gz_header) *head = calloc(256, 1);
PREFIX3(stream) c_stream; /* compression stream */
int err;
/* ===========================================================================
* Test deflateTune() with small buffers
*/
-void test_deflate_tune(unsigned char *compr, size_t comprLen)
-{
+void test_deflate_tune(unsigned char *compr, size_t comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
int good_length = 3;
/* ===========================================================================
* Usage: example [output.gz [input.gz]]
*/
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
unsigned char *compr, *uncompr;
z_size_t comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
z_size_t uncomprLen = comprLen;
#endif
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) {
- uint32_t crc0 = PREFIX(crc32)(0L, NULL, 0);
- uint32_t crc1 = crc0;
- uint32_t crc2 = crc0;
- uint32_t adler0 = PREFIX(adler32)(0L, NULL, 0);
- uint32_t adler1 = adler0;
- uint32_t adler2 = adler0;
- uint32_t combine1, combine2;
- /* Checksum with a buffer of size equal to the first byte in the input. */
- uint32_t buffSize = data[0];
- uint32_t offset = 0;
- uint32_t op[32];
+ uint32_t crc0 = PREFIX(crc32)(0L, NULL, 0);
+ uint32_t crc1 = crc0;
+ uint32_t crc2 = crc0;
+ uint32_t adler0 = PREFIX(adler32)(0L, NULL, 0);
+ uint32_t adler1 = adler0;
+ uint32_t adler2 = adler0;
+ uint32_t combine1, combine2;
+ /* Checksum with a buffer of size equal to the first byte in the input. */
+ uint32_t buffSize = data[0];
+ uint32_t offset = 0;
+ uint32_t op[32];
- /* Discard inputs larger than 1Mb. */
- static size_t kMaxSize = 1024 * 1024;
- if (dataLen < 1 || dataLen > kMaxSize)
- return 0;
+ /* Discard inputs larger than 1Mb. */
+ static size_t kMaxSize = 1024 * 1024;
+ if (dataLen < 1 || dataLen > kMaxSize)
+ return 0;
- /* Make sure the buffer has at least a byte. */
- if (buffSize == 0)
- ++buffSize;
+ /* Make sure the buffer has at least a byte. */
+ if (buffSize == 0)
+ ++buffSize;
- /* CRC32 */
- PREFIX(crc32_combine_gen)(op, buffSize);
- for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) {
- uint32_t crc3 = PREFIX(crc32_z)(crc0, data + offset, buffSize);
- uint32_t crc4 = PREFIX(crc32_combine_op)(crc1, crc3, op);
- crc1 = PREFIX(crc32_z)(crc1, data + offset, buffSize);
- assert(crc1 == crc4);
- (void)crc1;
- (void)crc4;
- }
- crc1 = PREFIX(crc32_z)(crc1, data + offset, dataLen % buffSize);
+ /* CRC32 */
+ PREFIX(crc32_combine_gen)(op, buffSize);
+ for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) {
+ uint32_t crc3 = PREFIX(crc32_z)(crc0, data + offset, buffSize);
+ uint32_t crc4 = PREFIX(crc32_combine_op)(crc1, crc3, op);
+ crc1 = PREFIX(crc32_z)(crc1, data + offset, buffSize);
+ assert(crc1 == crc4);
+ (void)crc1;
+ (void)crc4;
+ }
+ crc1 = PREFIX(crc32_z)(crc1, data + offset, dataLen % buffSize);
- crc2 = PREFIX(crc32_z)(crc2, data, dataLen);
+ crc2 = PREFIX(crc32_z)(crc2, data, dataLen);
- assert(crc1 == crc2);
- (void)crc1;
- (void)crc2;
- combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen);
- combine2 = PREFIX(crc32_combine)(crc1, crc1, (z_off_t)dataLen);
- assert(combine1 == combine2);
+ assert(crc1 == crc2);
+ (void)crc1;
+ (void)crc2;
+ combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen);
+ combine2 = PREFIX(crc32_combine)(crc1, crc1, (z_off_t)dataLen);
+ assert(combine1 == combine2);
- /* Fast CRC32 combine. */
- PREFIX(crc32_combine_gen)(op, (z_off_t)dataLen);
- combine1 = PREFIX(crc32_combine_op)(crc1, crc2, op);
- combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op);
- assert(combine1 == combine2);
- combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen);
- combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op);
- assert(combine1 == combine2);
+ /* Fast CRC32 combine. */
+ PREFIX(crc32_combine_gen)(op, (z_off_t)dataLen);
+ combine1 = PREFIX(crc32_combine_op)(crc1, crc2, op);
+ combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op);
+ assert(combine1 == combine2);
+ combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen);
+ combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op);
+ assert(combine1 == combine2);
- /* Adler32 */
- for (offset = 0; offset + buffSize <= dataLen; offset += buffSize)
- adler1 = PREFIX(adler32_z)(adler1, data + offset, buffSize);
- adler1 = PREFIX(adler32_z)(adler1, data + offset, dataLen % buffSize);
+ /* Adler32 */
+ for (offset = 0; offset + buffSize <= dataLen; offset += buffSize)
+ adler1 = PREFIX(adler32_z)(adler1, data + offset, buffSize);
+ adler1 = PREFIX(adler32_z)(adler1, data + offset, dataLen % buffSize);
- adler2 = PREFIX(adler32_z)(adler2, data, dataLen);
+ adler2 = PREFIX(adler32_z)(adler2, data, dataLen);
- assert(adler1 == adler2);
- (void)adler1;
- (void)adler2;
- combine1 = PREFIX(adler32_combine)(adler1, adler2, (z_off_t)dataLen);
- combine2 = PREFIX(adler32_combine)(adler1, adler1, (z_off_t)dataLen);
- assert(combine1 == combine2);
+ assert(adler1 == adler2);
+ (void)adler1;
+ (void)adler2;
+ combine1 = PREFIX(adler32_combine)(adler1, adler2, (z_off_t)dataLen);
+ combine2 = PREFIX(adler32_combine)(adler1, adler1, (z_off_t)dataLen);
+ assert(combine1 == combine2);
- /* This function must return 0. */
- return 0;
+ /* This function must return 0. */
+ return 0;
}
/* ===========================================================================
* Test deflate() with preset dictionary
*/
-void test_dict_deflate(unsigned char **compr, size_t *comprLen)
-{
+void test_dict_deflate(unsigned char **compr, size_t *comprLen) {
PREFIX3(stream) c_stream; /* compression stream */
int err;
int level = data[0] % 11 - 1; /* [-1..9]
/* deflate would fail for no-compression or for speed levels. */
if (level == 0 || level == 1)
- level = -1;
+ level = -1;
c_stream.zalloc = zalloc;
c_stream.zfree = zfree;
#include "zbuild.h"
#ifdef ZLIB_COMPAT
-# include "zlib.h"
+# include "zlib.h"
#else
-# include "zlib-ng.h"
+# include "zlib-ng.h"
#endif
#include <stdio.h>
#include <assert.h>
#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
- extern int unlink (const char *);
+extern int unlink (const char *);
#endif
#endif
/* ===========================================================================
* Display error message and exit
*/
-void error(const char *msg)
-{
+void error(const char *msg) {
fprintf(stderr, "%s: %s\n", prog, msg);
exit(1);
}
* Compress input to output then close both files.
*/
-void gz_compress(FILE *in, gzFile out)
-{
+void gz_compress(FILE *in, gzFile out) {
char buf[BUFLEN];
int len;
int err;
/* Try compressing the input file at once using mmap. Return Z_OK if
* if success, Z_ERRNO otherwise.
*/
-int gz_compress_mmap(FILE *in, gzFile out)
-{
+int gz_compress_mmap(FILE *in, gzFile out) {
int len;
int err;
int ifd = fileno(in);
/* ===========================================================================
* Uncompress input to output then close both files.
*/
-void gz_uncompress(gzFile in, FILE *out)
-{
+void gz_uncompress(gzFile in, FILE *out) {
char buf[BUFLENW];
int len;
int err;
* Compress the given file: create a corresponding .gz file and remove the
* original.
*/
-void file_compress(char *file, char *mode)
-{
+void file_compress(char *file, char *mode) {
char outfile[MAX_NAME_LEN];
- FILE *in;
+ FILE *in;
gzFile out;
if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
/* ===========================================================================
* Uncompress the given file and remove the original.
*/
-void file_uncompress(char *file)
-{
+void file_uncompress(char *file) {
char buf[MAX_NAME_LEN];
char *infile, *outfile;
- FILE *out;
+ FILE *out;
gzFile in;
size_t len = strlen(file);
};
/* memory allocation routine to pass to zlib */
-static void *mem_alloc(void *mem, unsigned count, unsigned size)
-{
+static void *mem_alloc(void *mem, unsigned count, unsigned size) {
void *ptr;
struct mem_item *item;
struct mem_zone *zone = mem;
}
/* memory free routine to pass to zlib */
-static void mem_free(void *mem, void *ptr)
-{
+static void mem_free(void *mem, void *ptr) {
struct mem_item *item, *next;
struct mem_zone *zone = mem;
/* set up a controlled memory allocation space for monitoring, set the stream
parameters to the controlled routines, with opaque pointing to the space */
-static void mem_setup(z_stream *strm)
-{
+static void mem_setup(z_stream *strm) {
struct mem_zone *zone;
zone = malloc(sizeof(struct mem_zone));
}
/* set a limit on the total memory allocation, or 0 to remove the limit */
-static void mem_limit(z_stream *strm, size_t limit)
-{
+static void mem_limit(z_stream *strm, size_t limit) {
struct mem_zone *zone = strm->opaque;
zone->limit = limit;
}
/* show the current total requested allocations in bytes */
-static void mem_used(z_stream *strm, char *prefix)
-{
+static void mem_used(z_stream *strm, char *prefix) {
struct mem_zone *zone = strm->opaque;
fprintf(stderr, "%s: %zu allocated\n", prefix, zone->total);
}
/* show the high water allocation in bytes */
-static void mem_high(z_stream *strm, char *prefix)
-{
+static void mem_high(z_stream *strm, char *prefix) {
struct mem_zone *zone = strm->opaque;
fprintf(stderr, "%s: %zu high water mark\n", prefix, zone->highwater);
}
/* release the memory allocation zone -- if there are any surprises, notify */
-static void mem_done(z_stream *strm, char *prefix)
-{
+static void mem_done(z_stream *strm, char *prefix) {
int count = 0;
struct mem_item *item, *next;
struct mem_zone *zone = strm->opaque;
by a delimiter, where that single digit writes a byte. The returned data is
allocated and must eventually be freed. NULL is returned if out of memory.
If the length is not needed, then len can be NULL. */
-static unsigned char *h2b(const char *hex, unsigned *len)
-{
+static unsigned char *h2b(const char *hex, unsigned *len) {
unsigned char *in, *re;
unsigned next, val;
header information is collected with inflateGetHeader(). If a zlib stream
is looking for a dictionary, then an empty dictionary is provided.
inflate() is run until all of the input data is consumed. */
-static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int err)
-{
+static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int err) {
int ret;
unsigned have;
unsigned char *in, *out;
}
/* cover all of the lines in inflate.c up to inflate() */
-static void cover_support(void)
-{
+static void cover_support(void) {
int ret;
z_stream strm;
}
/* cover all inflate() header and trailer cases and code after inflate() */
-static void cover_wrap(void)
-{
+static void cover_wrap(void) {
int ret;
z_stream strm, copy;
unsigned char dict[257];
}
/* input and output functions for inflateBack() */
-static unsigned pull(void *desc, const unsigned char **buf)
-{
+static unsigned pull(void *desc, const unsigned char **buf) {
static unsigned int next = 0;
static unsigned char dat[] = {0x63, 0, 2, 0};
struct inflate_state *state;
return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
}
-static int push(void *desc, unsigned char *buf, unsigned len)
-{
+static int push(void *desc, unsigned char *buf, unsigned len) {
buf += len;
return desc != NULL; /* force error if desc not null */
}
/* cover inflateBack() up to common deflate data cases and after those */
-static void cover_back(void)
-{
+static void cover_back(void) {
int ret;
z_stream strm;
unsigned char win[32768];
}
/* do a raw inflate of data in hexadecimal with both inflate and inflateBack */
-static int try(char *hex, char *id, int err)
-{
+static int try(char *hex, char *id, int err) {
int ret;
unsigned len, size;
unsigned char *in, *out, *win;
}
/* cover deflate data cases in both inflate() and inflateBack() */
-static void cover_inflate(void)
-{
+static void cover_inflate(void) {
try("0 0 0 0 0", "invalid stored block lengths", 1);
try("3 0", "fixed", 0);
try("6", "invalid block type", 1);
}
/* cover remaining lines in inftrees.c */
-static void cover_trees(void)
-{
+static void cover_trees(void) {
int ret;
unsigned bits;
uint16_t lens[16], work[16];
}
/* cover remaining inffast.c decoding and window copying */
-static void cover_fast(void)
-{
+static void cover_fast(void) {
inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68"
" ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR);
inf("25 fd 81 b5 6d 59 b6 6a 49 ea af 35 6 34 eb 8c b9 f6 b9 1e ef 67 49"
Z_STREAM_END);
}
-int main(void)
-{
+int main(void) {
fprintf(stderr, "%s\n", zlibVersion());
cover_support();
cover_wrap();
#include "zbuild.h"
#ifdef ZLIB_COMPAT
-# include "zlib.h"
+# include "zlib.h"
#else
-# include "zlib-ng.h"
+# include "zlib-ng.h"
#endif
#include <stdio.h>
#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
- extern int unlink (const char *);
+extern int unlink (const char *);
#endif
#endif
#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
#if defined(S390_DFLTCC_DEFLATE) || defined(S390_DFLTCC_INFLATE)
-#define BUFLEN 262144 /* DFLTCC works faster with larger buffers */
+# define BUFLEN 262144 /* DFLTCC works faster with larger buffers */
#else
-#define BUFLEN 16384 /* read buffer size */
+# define BUFLEN 16384 /* read buffer size */
#endif
#define BUFLENW (BUFLEN * 3) /* write buffer size */
#define MAX_NAME_LEN 1024
static char *prog;
void error (const char *msg);
-void gz_compress (FILE *in, gzFile out);
+void gz_compress (FILE *in, gzFile out);
#ifdef USE_MMAP
-int gz_compress_mmap (FILE *in, gzFile out);
+int gz_compress_mmap (FILE *in, gzFile out);
#endif
-void gz_uncompress (gzFile in, FILE *out);
-void file_compress (char *file, char *mode);
-void file_uncompress (char *file);
+void gz_uncompress (gzFile in, FILE *out);
+void file_compress (char *file, char *mode);
+void file_uncompress (char *file);
int main (int argc, char *argv[]);
/* ===========================================================================
* Display error message and exit
*/
-void error(const char *msg)
-{
+void error(const char *msg) {
fprintf(stderr, "%s: %s\n", prog, msg);
exit(1);
}
* Compress input to output then close both files.
*/
-void gz_compress(FILE *in, gzFile out)
-{
+void gz_compress(FILE *in, gzFile out) {
char buf[BUFLEN];
int len;
int err;
/* Try compressing the input file at once using mmap. Return Z_OK if
* if success, Z_ERRNO otherwise.
*/
-int gz_compress_mmap(FILE *in, gzFile out)
-{
+int gz_compress_mmap(FILE *in, gzFile out) {
int len;
int err;
int ifd = fileno(in);
/* ===========================================================================
* Uncompress input to output then close both files.
*/
-void gz_uncompress(gzFile in, FILE *out)
-{
+void gz_uncompress(gzFile in, FILE *out) {
char buf[BUFLENW];
int len;
int err;
* Compress the given file: create a corresponding .gz file and remove the
* original.
*/
-void file_compress(char *file, char *mode)
-{
+void file_compress(char *file, char *mode) {
char outfile[MAX_NAME_LEN];
- FILE *in;
+ FILE *in;
gzFile out;
if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
/* ===========================================================================
* Uncompress the given file and remove the original.
*/
-void file_uncompress(char *file)
-{
+void file_uncompress(char *file) {
char buf[MAX_NAME_LEN];
char *infile, *outfile;
- FILE *out;
+ FILE *out;
gzFile in;
size_t len = strlen(file);
* -0 to -9 : compression level
*/
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
int copyout = 0;
int uncompr = 0;
int i = 0;
prog = argv[i];
bname = strrchr(argv[i], '/');
if (bname)
- bname++;
+ bname++;
else
- bname = argv[i];
+ bname = argv[i];
if (!strcmp(bname, "gunzip"))
- uncompr = 1;
+ uncompr = 1;
else if (!strcmp(bname, "zcat"))
- copyout = uncompr = 1;
+ copyout = uncompr = 1;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-c") == 0)
else if (strcmp(argv[i], "-A") == 0)
type = "";
else if (argv[i][0] == '-' && (argv[i][1] == 'f' || argv[i][1] == 'h' ||
- argv[i][1] == 'R' || argv[i][1] == 'F' || argv[i][1] == 'T') && argv[i][2] == 0)
+ argv[i][1] == 'R' || argv[i][1] == 'F' || argv[i][1] == 'T') && argv[i][2] == 0)
strategy = argv[i] + 1;
else if (argv[i][0] == '-' && argv[i][1] >= '0' && argv[i][1] <= '9' && argv[i][2] == 0)
level = argv[i] + 1;
#include <stdlib.h>
#include <string.h>
-static int read_all(unsigned char *buf, size_t size)
-{
+static int read_all(unsigned char *buf, size_t size) {
for (size_t total_read = 0; total_read < size;) {
size_t n_read = fread(buf + total_read, 1, size - total_read, stdin);
if (ferror(stdin)) {
return 0;
}
-static int write_all(unsigned char *buf, size_t size)
-{
+static int write_all(unsigned char *buf, size_t size) {
for (size_t total_written = 0; total_written < size;) {
size_t n_written = fwrite(buf + total_written, 1, size - total_written, stdout);
if (ferror(stdout)) {
return 0;
}
-static int compress_chunk(PREFIX3(stream) *strm, int level, int size, int last)
-{
+static int compress_chunk(PREFIX3(stream) *strm, int level, int size, int last) {
int ret = 1;
int err = PREFIX(deflateParams)(strm, level, Z_DEFAULT_STRATEGY);
if (err != Z_OK) {
* Usage: switchlevels level1 size1 [level2 size2 ...]
*/
-int main(int argc, char **argv)
-{
+int main(int argc, char **argv) {
int ret = EXIT_FAILURE;
PREFIX3(stream) strm;
memset(&strm, 0, sizeof(strm));
printf("%2u%s", dist_code[i], SEPARATOR(i, DIST_CODE_LEN-1, 20));
}
- printf("const unsigned char ZLIB_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
+ printf("const unsigned char ZLIB_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1] = {\n");
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
printf("%2u%s", length_code[i], SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
}
int min_count = 4; /* min repeat count */
if (nextlen == 0)
- max_count = 138, min_count = 3;
+ max_count = 138, min_count = 3;
tree[max_code+1].Len = (uint16_t)0xffff; /* guard */
if (buf != NULL) { /* force stored block */
#else
if (stored_len+4 <= opt_lenb && buf != NULL) {
- /* 4: two words for the lengths */
+ /* 4: two words for the lengths */
#endif
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
* Otherwise we can't have processed more than WSIZE input bytes since
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
};
-const unsigned char ZLIB_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1]= {
+const unsigned char ZLIB_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
#define ZLIB_INTERNAL
#include "zbuild.h"
#ifdef ZLIB_COMPAT
-# include "zlib.h"
+# include "zlib.h"
#else
-# include "zlib-ng.h"
+# include "zlib-ng.h"
#endif
/* ===========================================================================
if (*destLen) {
left = *destLen;
*destLen = 0;
- }
- else {
+ } else {
left = 1;
dest = buf;
}
err;
}
-int ZEXPORT PREFIX(uncompress)(unsigned char *dest, z_size_t *destLen, const unsigned char *source, z_size_t sourceLen)
-{
+int ZEXPORT PREFIX(uncompress)(unsigned char *dest, z_size_t *destLen, const unsigned char *source, z_size_t sourceLen) {
return PREFIX(uncompress2)(dest, destLen, source, &sourceLen);
}
/* First check whether the compiler knows the target __BYTE_ORDER__. */
#if defined(__BYTE_ORDER__)
-# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-# if !defined(LITTLE_ENDIAN)
-# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
-# endif
-# if !defined(BYTE_ORDER)
-# define BYTE_ORDER LITTLE_ENDIAN
-# endif
-# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-# if !defined(BIG_ENDIAN)
-# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
-# endif
-# if !defined(BYTE_ORDER)
-# define BYTE_ORDER BIG_ENDIAN
+# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# if !defined(LITTLE_ENDIAN)
+# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+# endif
+# if !defined(BYTE_ORDER)
+# define BYTE_ORDER LITTLE_ENDIAN
+# endif
+# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# if !defined(BIG_ENDIAN)
+# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
+# endif
+# if !defined(BYTE_ORDER)
+# define BYTE_ORDER BIG_ENDIAN
+# endif
# endif
-# endif
#elif defined(__MINGW32__)
-# include <sys/param.h>
+# include <sys/param.h>
#elif defined(WIN32) || defined(_WIN32)
-# define LITTLE_ENDIAN 1234
-# define BIG_ENDIAN 4321
-# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined (_M_ARM) || defined (_M_ARM64)
-# define BYTE_ORDER LITTLE_ENDIAN
-# else
-# error Unknown endianness!
-# endif
+# define LITTLE_ENDIAN 1234
+# define BIG_ENDIAN 4321
+# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined (_M_ARM) || defined (_M_ARM64)
+# define BYTE_ORDER LITTLE_ENDIAN
+# else
+# error Unknown endianness!
+# endif
#elif defined(__linux__)
-# include <endian.h>
+# include <endian.h>
#elif defined(__APPLE__) || defined(__arm__) || defined(__aarch64__)
-# include <machine/endian.h>
+# include <machine/endian.h>
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
-# include <sys/endian.h>
+# include <sys/endian.h>
#elif defined(__sun) || defined(sun)
-# include <sys/byteorder.h>
-# if !defined(LITTLE_ENDIAN)
-# define LITTLE_ENDIAN 4321
-# endif
-# if !defined(BIG_ENDIAN)
-# define BIG_ENDIAN 1234
-# endif
-# if !defined(BYTE_ORDER)
-# if defined(_BIG_ENDIAN)
-# define BYTE_ORDER BIG_ENDIAN
-# else
-# define BYTE_ORDER LITTLE_ENDIAN
+# include <sys/byteorder.h>
+# if !defined(LITTLE_ENDIAN)
+# define LITTLE_ENDIAN 4321
+# endif
+# if !defined(BIG_ENDIAN)
+# define BIG_ENDIAN 1234
+# endif
+# if !defined(BYTE_ORDER)
+# if defined(_BIG_ENDIAN)
+# define BYTE_ORDER BIG_ENDIAN
+# else
+# define BYTE_ORDER LITTLE_ENDIAN
+# endif
# endif
-# endif
#else
-# include <endian.h>
+# include <endian.h>
#endif
#endif
ZEXTERN ZEXPORT int zng_deflateResetKeep (zng_stream *);
#ifdef WITH_GZFILEOP
-# if (defined(WIN32) || defined(__MINGW__))
- ZEXTERN ZEXPORT gzFile zng_gzopen_w(const wchar_t *path, const char *mode);
-# endif
+# if (defined(WIN32) || defined(__MINGW__))
+ ZEXTERN ZEXPORT gzFile zng_gzopen_w(const wchar_t *path, const char *mode);
+# endif
ZEXTERN ZEXPORTVA int zng_gzvprintf(gzFile file, const char *format, va_list va);
#endif
not perform any compression: this will be done by deflate().
*/
-ZEXTERN int ZEXPORT deflateGetDictionary (z_stream *strm, unsigned char *dictionary, unsigned int *dictLength);
+ZEXTERN int ZEXPORT deflateGetDictionary (z_stream *strm, unsigned char *dictionary, unsigned int *dictLength);
/*
Returns the sliding dictionary being maintained by deflate. dictLength is
set to the number of bytes in the dictionary, and that many bytes are copied
# include "gzguts.h"
#endif
#ifndef UNALIGNED_OK
-# include "malloc.h"
+# include <malloc.h>
#endif
const char * const zng_errmsg[10] = {
};
const char zlibng_string[] =
- " zlib-ng 1.9.9 forked from zlib 1.2.11 ";
+ " zlib-ng 1.9.9 forked from zlib 1.2.11 ";
#ifdef ZLIB_COMPAT
-const char * ZEXPORT zlibVersion(void)
-{
+const char * ZEXPORT zlibVersion(void) {
return ZLIB_VERSION;
}
#endif
-const char * ZEXPORT zlibng_version(void)
-{
+const char * ZEXPORT zlibng_version(void) {
return ZLIBNG_VERSION;
}
-unsigned long ZEXPORT PREFIX(zlibCompileFlags)(void)
-{
+unsigned long ZEXPORT PREFIX(zlibCompileFlags)(void) {
unsigned long flags;
flags = 0;
}
#ifdef ZLIB_DEBUG
-#include <stdlib.h>
+# include <stdlib.h>
# ifndef verbose
# define verbose 0
# endif
int ZLIB_INTERNAL z_verbose = verbose;
-void ZLIB_INTERNAL z_error (m)
- char *m;
-{
+void ZLIB_INTERNAL z_error(char *m) {
fprintf(stderr, "%s\n", m);
exit(1);
}
/* exported to allow conversion of error code to string for compress() and
* uncompress()
*/
-const char * ZEXPORT PREFIX(zError)(int err)
-{
+const char * ZEXPORT PREFIX(zError)(int err) {
return ERR_MSG(err);
}
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
-void ZLIB_INTERNAL *zng_calloc (void *opaque, unsigned items, unsigned size)
-{
+void ZLIB_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size) {
(void)opaque;
#ifndef UNALIGNED_OK
return memalign(16, items * size);
#endif
}
-void ZLIB_INTERNAL zng_cfree (void *opaque, void *ptr)
-{
+void ZLIB_INTERNAL zng_cfree(void *opaque, void *ptr) {
(void)opaque;
free(ptr);
}
#include <stdlib.h>
#include <stdint.h>
#ifdef ZLIB_COMPAT
-# include "zlib.h"
+# include "zlib.h"
#else
-# include "zlib-ng.h"
+# include "zlib-ng.h"
#endif
typedef unsigned char uch; /* Included for compatibility with external code only */
typedef uint16_t ush; /* Included for compatibility with external code only */
-typedef unsigned long ulg;
+typedef unsigned long ulg;
extern const char * const zng_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */
/* provide prototypes for these when building zlib without LFS */
#if !defined(WIN32) && !defined(__MSYS__) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
-# include "zbuild.h" /* For PREFIX() */
+# include "zbuild.h" /* For PREFIX() */
ZEXTERN uint32_t ZEXPORT PREFIX(adler32_combine64)(uint32_t, uint32_t, z_off_t);
ZEXTERN uint32_t ZEXPORT PREFIX(crc32_combine64)(uint32_t, uint32_t, z_off_t);
#endif
/* Diagnostic functions */
#ifdef ZLIB_DEBUG
-# include <stdio.h>
- extern int ZLIB_INTERNAL z_verbose;
- extern void ZLIB_INTERNAL z_error(char *m);
-# define Assert(cond, msg) {if(!(cond)) z_error(msg);}
-# define Trace(x) {if (z_verbose >= 0) fprintf x;}
-# define Tracev(x) {if (z_verbose > 0) fprintf x;}
-# define Tracevv(x) {if (z_verbose > 1) fprintf x;}
-# define Tracec(c, x) {if (z_verbose > 0 && (c)) fprintf x;}
-# define Tracecv(c, x) {if (z_verbose > 1 && (c)) fprintf x;}
+# include <stdio.h>
+ extern int ZLIB_INTERNAL z_verbose;
+ extern void ZLIB_INTERNAL z_error(char *m);
+# define Assert(cond, msg) {if (!(cond)) z_error(msg);}
+# define Trace(x) {if (z_verbose >= 0) fprintf x;}
+# define Tracev(x) {if (z_verbose > 0) fprintf x;}
+# define Tracevv(x) {if (z_verbose > 1) fprintf x;}
+# define Tracec(c, x) {if (z_verbose > 0 && (c)) fprintf x;}
+# define Tracecv(c, x) {if (z_verbose > 1 && (c)) fprintf x;}
#else
-# define Assert(cond, msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c, x)
-# define Tracecv(c, x)
+# define Assert(cond, msg)
+# define Trace(x)
+# define Tracev(x)
+# define Tracevv(x)
+# define Tracec(c, x)
+# define Tracecv(c, x)
#endif
void ZLIB_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size);
#define ZALLOC(strm, items, size) (*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (void *)(addr))
-#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
/* Reverse the bytes in a value. Use compiler intrinsics when
possible to take advantage of hardware implementations. */
/* Only enable likely/unlikely if the compiler is known to support it */
#if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__INTEL_COMPILER) || defined(__Clang__)
-# define LIKELY_NULL(x) __builtin_expect((x) != 0, 0)
-# define LIKELY(x) __builtin_expect(!!(x), 1)
-# define UNLIKELY(x) __builtin_expect(!!(x), 0)
-# define PREFETCH_L1(addr) __builtin_prefetch(addr, 0, 3)
-# define PREFETCH_L2(addr) __builtin_prefetch(addr, 0, 2)
-# define PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 2)
+# define LIKELY_NULL(x) __builtin_expect((x) != 0, 0)
+# define LIKELY(x) __builtin_expect(!!(x), 1)
+# define UNLIKELY(x) __builtin_expect(!!(x), 0)
+# define PREFETCH_L1(addr) __builtin_prefetch(addr, 0, 3)
+# define PREFETCH_L2(addr) __builtin_prefetch(addr, 0, 2)
+# define PREFETCH_RW(addr) __builtin_prefetch(addr, 1, 2)
#elif defined(__WIN__)
-# include <xmmintrin.h>
-# define LIKELY_NULL(x) x
-# define LIKELY(x) x
-# define UNLIKELY(x) x
-# define PREFETCH_L1(addr) _mm_prefetch((char *) addr, _MM_HINT_T0)
-# define PREFETCH_L2(addr) _mm_prefetch((char *) addr, _MM_HINT_T1)
-# define PREFETCH_RW(addr) _mm_prefetch((char *) addr, _MM_HINT_T1)
+# include <xmmintrin.h>
+# define LIKELY_NULL(x) x
+# define LIKELY(x) x
+# define UNLIKELY(x) x
+# define PREFETCH_L1(addr) _mm_prefetch((char *) addr, _MM_HINT_T0)
+# define PREFETCH_L2(addr) _mm_prefetch((char *) addr, _MM_HINT_T1)
+# define PREFETCH_RW(addr) _mm_prefetch((char *) addr, _MM_HINT_T1)
#else
-# define LIKELY_NULL(x) x
-# define LIKELY(x) x
-# define UNLIKELY(x) x
-# define PREFETCH_L1(addr) addr
-# define PREFETCH_L2(addr) addr
-# define PREFETCH_RW(addr) addr
+# define LIKELY_NULL(x) x
+# define LIKELY(x) x
+# define UNLIKELY(x) x
+# define PREFETCH_L1(addr) addr
+# define PREFETCH_L2(addr) addr
+# define PREFETCH_RW(addr) addr
#endif /* (un)likely */
#if defined(_MSC_VER)
-#define ALIGNED_(x) __declspec(align(x))
+# define ALIGNED_(x) __declspec(align(x))
#else
-#if defined(__GNUC__)
-#define ALIGNED_(x) __attribute__ ((aligned(x)))
-#endif
+# if defined(__GNUC__)
+# define ALIGNED_(x) __attribute__ ((aligned(x)))
+# endif
#endif
#if defined(X86_CPUID)
-# include "arch/x86/x86.h"
+# include "arch/x86/x86.h"
#elif defined(ARM_GETAUXVAL)
-# include "arch/arm/arm.h"
+# include "arch/arm/arm.h"
#endif
#endif /* ZUTIL_H_ */