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