You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zstd_deps.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under both the BSD-style license (found in the
  6. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7. * in the COPYING file in the root directory of this source tree).
  8. * You may select, at your option, one of the above-listed licenses.
  9. */
  10. /* This file provides common libc dependencies that zstd requires.
  11. * The purpose is to allow replacing this file with a custom implementation
  12. * to compile zstd without libc support.
  13. */
  14. /* Need:
  15. * NULL
  16. * INT_MAX
  17. * UINT_MAX
  18. * ZSTD_memcpy()
  19. * ZSTD_memset()
  20. * ZSTD_memmove()
  21. */
  22. #ifndef ZSTD_DEPS_COMMON
  23. #define ZSTD_DEPS_COMMON
  24. #include <limits.h>
  25. #include <stddef.h>
  26. #include <string.h>
  27. #if defined(__GNUC__) && __GNUC__ >= 4
  28. # define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
  29. # define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
  30. # define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))
  31. #else
  32. # define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))
  33. # define ZSTD_memmove(d,s,l) memmove((d),(s),(l))
  34. # define ZSTD_memset(p,v,l) memset((p),(v),(l))
  35. #endif
  36. #endif /* ZSTD_DEPS_COMMON */
  37. /* Need:
  38. * ZSTD_malloc()
  39. * ZSTD_free()
  40. * ZSTD_calloc()
  41. */
  42. #ifdef ZSTD_DEPS_NEED_MALLOC
  43. #ifndef ZSTD_DEPS_MALLOC
  44. #define ZSTD_DEPS_MALLOC
  45. #include <stdlib.h>
  46. #define ZSTD_malloc(s) malloc(s)
  47. #define ZSTD_calloc(n,s) calloc((n), (s))
  48. #define ZSTD_free(p) free((p))
  49. #endif /* ZSTD_DEPS_MALLOC */
  50. #endif /* ZSTD_DEPS_NEED_MALLOC */
  51. /*
  52. * Provides 64-bit math support.
  53. * Need:
  54. * U64 ZSTD_div64(U64 dividend, U32 divisor)
  55. */
  56. #ifdef ZSTD_DEPS_NEED_MATH64
  57. #ifndef ZSTD_DEPS_MATH64
  58. #define ZSTD_DEPS_MATH64
  59. #define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))
  60. #endif /* ZSTD_DEPS_MATH64 */
  61. #endif /* ZSTD_DEPS_NEED_MATH64 */
  62. /* Need:
  63. * assert()
  64. */
  65. #ifdef ZSTD_DEPS_NEED_ASSERT
  66. #ifndef ZSTD_DEPS_ASSERT
  67. #define ZSTD_DEPS_ASSERT
  68. #include <assert.h>
  69. #endif /* ZSTD_DEPS_ASSERT */
  70. #endif /* ZSTD_DEPS_NEED_ASSERT */
  71. /* Need:
  72. * ZSTD_DEBUG_PRINT()
  73. */
  74. #ifdef ZSTD_DEPS_NEED_IO
  75. #ifndef ZSTD_DEPS_IO
  76. #define ZSTD_DEPS_IO
  77. #include <stdio.h>
  78. #define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
  79. #endif /* ZSTD_DEPS_IO */
  80. #endif /* ZSTD_DEPS_NEED_IO */
  81. /* Only requested when <stdint.h> is known to be present.
  82. * Need:
  83. * intptr_t
  84. */
  85. #ifdef ZSTD_DEPS_NEED_STDINT
  86. #ifndef ZSTD_DEPS_STDINT
  87. #define ZSTD_DEPS_STDINT
  88. #include <stdint.h>
  89. #endif /* ZSTD_DEPS_STDINT */
  90. #endif /* ZSTD_DEPS_NEED_STDINT */