vogl_miniz_common.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // File: vogl_miniz_common.h
  27. #pragma once
  28. //#include "vogl_core.h"
  29. #include <inttypes.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <assert.h>
  33. #define MZ_ASSERT(x) assert(x)
  34. #ifdef MINIZ_NO_MALLOC
  35. #define MZ_MALLOC(x) NULL
  36. #define MZ_FREE(x) (void) x, ((void)0)
  37. #define MZ_REALLOC(p, x) NULL
  38. #else
  39. #define MZ_MALLOC(x) malloc(x)
  40. #define MZ_FREE(x) free(x)
  41. #define MZ_REALLOC(p, x) realloc(p, x)
  42. #endif
  43. #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b))
  44. #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b))
  45. #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
  46. #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
  47. #define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
  48. #define MZ_READ_LE32(p) *((const mz_uint32 *)(p))
  49. #else
  50. #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
  51. #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))
  52. #endif
  53. #define MZ_READ_LE64(p) (((mz_uint64)MZ_READ_LE32(p)) | (((mz_uint64)MZ_READ_LE32((const mz_uint8 *)(p) + sizeof(mz_uint32))) << 32U))
  54. #ifdef COMPILER_MSVC
  55. #define MZ_FORCEINLINE __forceinline
  56. #elif defined(COMPILER_GCCLIKE)
  57. #define MZ_FORCEINLINE inline __attribute__((__always_inline__))
  58. #else
  59. #define MZ_FORCEINLINE inline
  60. #endif
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. extern void *miniz_def_alloc_func(void *opaque, size_t items, size_t size);
  65. extern void miniz_def_free_func(void *opaque, void *address);
  66. extern void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size);
  67. #define MZ_UINT16_MAX (0xFFFFU)
  68. #define MZ_UINT32_MAX (0xFFFFFFFFU)
  69. #ifdef __cplusplus
  70. }
  71. #endif