2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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.
11 /* This file provides common libc dependencies that zstd requires.
12 * The purpose is to allow replacing this file with a custom implementation
13 * to compile zstd without libc support.
24 #ifndef ZSTD_DEPS_COMMON
25 #define ZSTD_DEPS_COMMON
31 #if defined(__GNUC__) && __GNUC__ >= 4
32 # define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
33 # define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
34 # define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))
36 # define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))
37 # define ZSTD_memmove(d,s,l) memmove((d),(s),(l))
38 # define ZSTD_memset(p,v,l) memset((p),(v),(l))
41 #endif /* ZSTD_DEPS_COMMON */
48 #ifdef ZSTD_DEPS_NEED_MALLOC
49 #ifndef ZSTD_DEPS_MALLOC
50 #define ZSTD_DEPS_MALLOC
54 #define ZSTD_malloc(s) malloc(s)
55 #define ZSTD_calloc(n,s) calloc((n), (s))
56 #define ZSTD_free(p) free((p))
58 #endif /* ZSTD_DEPS_MALLOC */
59 #endif /* ZSTD_DEPS_NEED_MALLOC */
62 * Provides 64-bit math support.
64 * U64 ZSTD_div64(U64 dividend, U32 divisor)
66 #ifdef ZSTD_DEPS_NEED_MATH64
67 #ifndef ZSTD_DEPS_MATH64
68 #define ZSTD_DEPS_MATH64
70 #define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))
72 #endif /* ZSTD_DEPS_MATH64 */
73 #endif /* ZSTD_DEPS_NEED_MATH64 */
78 #ifdef ZSTD_DEPS_NEED_ASSERT
79 #ifndef ZSTD_DEPS_ASSERT
80 #define ZSTD_DEPS_ASSERT
84 #endif /* ZSTD_DEPS_ASSERT */
85 #endif /* ZSTD_DEPS_NEED_ASSERT */
90 #ifdef ZSTD_DEPS_NEED_IO
95 #define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
97 #endif /* ZSTD_DEPS_IO */
98 #endif /* ZSTD_DEPS_NEED_IO */
100 /* Only requested when <stdint.h> is known to be present.
104 #ifdef ZSTD_DEPS_NEED_STDINT
105 #ifndef ZSTD_DEPS_STDINT
106 #define ZSTD_DEPS_STDINT
110 #endif /* ZSTD_DEPS_STDINT */
111 #endif /* ZSTD_DEPS_NEED_STDINT */