1 #pragma once 2 #include <assert.h> 3 #include <stdint.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 #include "miniz_export.h" 8 9 /* ------------------- Types and macros */ 10 typedef unsigned char mz_uint8; 11 typedef signed short mz_int16; 12 typedef unsigned short mz_uint16; 13 typedef unsigned int mz_uint32; 14 typedef unsigned int mz_uint; 15 typedef int64_t mz_int64; 16 typedef uint64_t mz_uint64; 17 typedef int mz_bool; 18 19 #define MZ_FALSE (0) 20 #define MZ_TRUE (1) 21 22 /* Works around MSVC's spammy "warning C4127: conditional expression is constant" message. */ 23 #ifdef _MSC_VER 24 #define MZ_MACRO_END while (0, 0) 25 #else 26 #define MZ_MACRO_END while (0) 27 #endif 28 29 #ifdef MINIZ_NO_STDIO 30 #define MZ_FILE void * 31 #else 32 #include <stdio.h> 33 #define MZ_FILE FILE 34 #endif /* #ifdef MINIZ_NO_STDIO */ 35 36 #ifdef MINIZ_NO_TIME 37 typedef struct mz_dummy_time_t_tag 38 { 39 int m_dummy; 40 } mz_dummy_time_t; 41 #define MZ_TIME_T mz_dummy_time_t 42 #else 43 #define MZ_TIME_T time_t 44 #endif 45 46 #define MZ_ASSERT(x) assert(x) 47 48 #ifdef MINIZ_NO_MALLOC 49 #define MZ_MALLOC(x) NULL 50 #define MZ_FREE(x) (void)x, ((void)0) 51 #define MZ_REALLOC(p, x) NULL 52 #else 53 #define MZ_MALLOC(x) malloc(x) 54 #define MZ_FREE(x) free(x) 55 #define MZ_REALLOC(p, x) realloc(p, x) 56 #endif 57 58 #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b)) 59 #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b)) 60 #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) 61 62 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN 63 #define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) 64 #define MZ_READ_LE32(p) *((const mz_uint32 *)(p)) 65 #else 66 #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U)) 67 #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U)) 68 #endif 69 70 #define MZ_READ_LE64(p) (((mz_uint64)MZ_READ_LE32(p)) | (((mz_uint64)MZ_READ_LE32((const mz_uint8 *)(p) + sizeof(mz_uint32))) << 32U)) 71 72 #ifdef _MSC_VER 73 #define MZ_FORCEINLINE __forceinline 74 #elif defined(__GNUC__) 75 #define MZ_FORCEINLINE __inline__ __attribute__((__always_inline__)) 76 #else 77 #define MZ_FORCEINLINE inline 78 #endif 79 80 #ifdef __cplusplus 81 extern "C" { 82 #endif 83 84 extern MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); 85 extern MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address); 86 extern MINIZ_EXPORT void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size); 87 88 #define MZ_UINT16_MAX (0xFFFFU) 89 #define MZ_UINT32_MAX (0xFFFFFFFFU) 90 91 #ifdef __cplusplus 92 } 93 #endif 94