]> git.cworth.org Git - vogl/blob - src/voglcore/vogl_miniz_common.h
Initial vogl checkin
[vogl] / src / voglcore / vogl_miniz_common.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 // File: vogl_miniz_common.h
28 #pragma once
29 #ifndef VOGL_MINIZ_COMMON_H
30 #define VOGL_MINIZ_COMMON_H
31
32 #include "vogl_core.h"
33
34 #include <stdlib.h>
35 #include <string.h>
36 #include <assert.h>
37
38 #define MZ_ASSERT(x) assert(x)
39
40 #ifdef MINIZ_NO_MALLOC
41 #define MZ_MALLOC(x) NULL
42 #define MZ_FREE(x) (void) x, ((void)0)
43 #define MZ_REALLOC(p, x) NULL
44 #else
45 #define MZ_MALLOC(x) vogl_malloc(x)
46 #define MZ_FREE(x) vogl_free(x)
47 #define MZ_REALLOC(p, x) vogl_realloc(p, x)
48 #endif
49
50 #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b))
51 #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b))
52 #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
53
54 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES &&MINIZ_LITTLE_ENDIAN
55 #define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
56 #define MZ_READ_LE32(p) *((const mz_uint32 *)(p))
57 #else
58 #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
59 #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))
60 #endif
61
62 #define MZ_READ_LE64(p) (((mz_uint64)MZ_READ_LE32(p)) | (((mz_uint64)MZ_READ_LE32((const mz_uint8 *)(p) + sizeof(mz_uint32))) << 32U))
63
64 #ifdef _MSC_VER
65 #define MZ_FORCEINLINE __forceinline
66 #elif defined(__GNUC__)
67 #define MZ_FORCEINLINE inline __attribute__((__always_inline__))
68 #else
69 #define MZ_FORCEINLINE inline
70 #endif
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75
76 extern void *miniz_def_alloc_func(void *opaque, size_t items, size_t size);
77 extern void miniz_def_free_func(void *opaque, void *address);
78 extern void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size);
79
80 #define MZ_UINT16_MAX (0xFFFFU)
81 #define MZ_UINT32_MAX (0xFFFFFFFFU)
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 #endif // VOGL_MINIZ_COMMON_H