Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/openzfs/module/zstd/lib/common/zstd_deps.h
178701 views
1
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only
2
/*
3
* Copyright (c) Meta Platforms, Inc. and affiliates.
4
* All rights reserved.
5
*
6
* This source code is licensed under both the BSD-style license (found in the
7
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
8
* in the COPYING file in the root directory of this source tree).
9
* You may select, at your option, one of the above-listed licenses.
10
*/
11
12
/* This file provides common libc dependencies that zstd requires.
13
* The purpose is to allow replacing this file with a custom implementation
14
* to compile zstd without libc support.
15
*/
16
17
/* Need:
18
* NULL
19
* INT_MAX
20
* UINT_MAX
21
* ZSTD_memcpy()
22
* ZSTD_memset()
23
* ZSTD_memmove()
24
*/
25
#ifndef ZSTD_DEPS_COMMON
26
#define ZSTD_DEPS_COMMON
27
28
/* Even though we use qsort_r only for the dictionary builder, the macro
29
* _GNU_SOURCE has to be declared *before* the inclusion of any standard
30
* header and the script 'combine.sh' combines the whole zstd source code
31
* in a single file.
32
*/
33
#if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \
34
defined(__CYGWIN__) || defined(__MSYS__)
35
#if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */
36
#define _GNU_SOURCE
37
#endif
38
#endif
39
40
#include <limits.h>
41
#include <stddef.h>
42
#include <string.h>
43
44
#if defined(__GNUC__) && __GNUC__ >= 4
45
# define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
46
# define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
47
# define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))
48
#else
49
# define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))
50
# define ZSTD_memmove(d,s,l) memmove((d),(s),(l))
51
# define ZSTD_memset(p,v,l) memset((p),(v),(l))
52
#endif
53
54
#endif /* ZSTD_DEPS_COMMON */
55
56
/* Need:
57
* ZSTD_malloc()
58
* ZSTD_free()
59
* ZSTD_calloc()
60
*/
61
#ifdef ZSTD_DEPS_NEED_MALLOC
62
#ifndef ZSTD_DEPS_MALLOC
63
#define ZSTD_DEPS_MALLOC
64
65
#include <stdlib.h>
66
67
#define ZSTD_malloc(s) malloc(s)
68
#define ZSTD_calloc(n,s) calloc((n), (s))
69
#define ZSTD_free(p) free((p))
70
71
#endif /* ZSTD_DEPS_MALLOC */
72
#endif /* ZSTD_DEPS_NEED_MALLOC */
73
74
/*
75
* Provides 64-bit math support.
76
* Need:
77
* U64 ZSTD_div64(U64 dividend, U32 divisor)
78
*/
79
#ifdef ZSTD_DEPS_NEED_MATH64
80
#ifndef ZSTD_DEPS_MATH64
81
#define ZSTD_DEPS_MATH64
82
83
#define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))
84
85
#endif /* ZSTD_DEPS_MATH64 */
86
#endif /* ZSTD_DEPS_NEED_MATH64 */
87
88
/* Need:
89
* assert()
90
*/
91
#ifdef ZSTD_DEPS_NEED_ASSERT
92
#ifndef ZSTD_DEPS_ASSERT
93
#define ZSTD_DEPS_ASSERT
94
95
#include <assert.h>
96
97
#endif /* ZSTD_DEPS_ASSERT */
98
#endif /* ZSTD_DEPS_NEED_ASSERT */
99
100
/* Need:
101
* ZSTD_DEBUG_PRINT()
102
*/
103
#ifdef ZSTD_DEPS_NEED_IO
104
#ifndef ZSTD_DEPS_IO
105
#define ZSTD_DEPS_IO
106
107
#include <stdio.h>
108
#define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
109
110
#endif /* ZSTD_DEPS_IO */
111
#endif /* ZSTD_DEPS_NEED_IO */
112
113
/* Only requested when <stdint.h> is known to be present.
114
* Need:
115
* intptr_t
116
*/
117
#ifdef ZSTD_DEPS_NEED_STDINT
118
#ifndef ZSTD_DEPS_STDINT
119
#define ZSTD_DEPS_STDINT
120
121
#include <stdint.h>
122
123
#endif /* ZSTD_DEPS_STDINT */
124
#endif /* ZSTD_DEPS_NEED_STDINT */
125
126