Path: blob/main/sys/contrib/openzfs/module/zstd/lib/common/zstd_deps.h
178701 views
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only1/*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 the6* LICENSE file in the root directory of this source tree) and the GPLv2 (found7* 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*/1011/* This file provides common libc dependencies that zstd requires.12* The purpose is to allow replacing this file with a custom implementation13* to compile zstd without libc support.14*/1516/* Need:17* NULL18* INT_MAX19* UINT_MAX20* ZSTD_memcpy()21* ZSTD_memset()22* ZSTD_memmove()23*/24#ifndef ZSTD_DEPS_COMMON25#define ZSTD_DEPS_COMMON2627/* Even though we use qsort_r only for the dictionary builder, the macro28* _GNU_SOURCE has to be declared *before* the inclusion of any standard29* header and the script 'combine.sh' combines the whole zstd source code30* in a single file.31*/32#if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \33defined(__CYGWIN__) || defined(__MSYS__)34#if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */35#define _GNU_SOURCE36#endif37#endif3839#include <limits.h>40#include <stddef.h>41#include <string.h>4243#if defined(__GNUC__) && __GNUC__ >= 444# define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))45# define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))46# define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))47#else48# define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))49# define ZSTD_memmove(d,s,l) memmove((d),(s),(l))50# define ZSTD_memset(p,v,l) memset((p),(v),(l))51#endif5253#endif /* ZSTD_DEPS_COMMON */5455/* Need:56* ZSTD_malloc()57* ZSTD_free()58* ZSTD_calloc()59*/60#ifdef ZSTD_DEPS_NEED_MALLOC61#ifndef ZSTD_DEPS_MALLOC62#define ZSTD_DEPS_MALLOC6364#include <stdlib.h>6566#define ZSTD_malloc(s) malloc(s)67#define ZSTD_calloc(n,s) calloc((n), (s))68#define ZSTD_free(p) free((p))6970#endif /* ZSTD_DEPS_MALLOC */71#endif /* ZSTD_DEPS_NEED_MALLOC */7273/*74* Provides 64-bit math support.75* Need:76* U64 ZSTD_div64(U64 dividend, U32 divisor)77*/78#ifdef ZSTD_DEPS_NEED_MATH6479#ifndef ZSTD_DEPS_MATH6480#define ZSTD_DEPS_MATH648182#define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))8384#endif /* ZSTD_DEPS_MATH64 */85#endif /* ZSTD_DEPS_NEED_MATH64 */8687/* Need:88* assert()89*/90#ifdef ZSTD_DEPS_NEED_ASSERT91#ifndef ZSTD_DEPS_ASSERT92#define ZSTD_DEPS_ASSERT9394#include <assert.h>9596#endif /* ZSTD_DEPS_ASSERT */97#endif /* ZSTD_DEPS_NEED_ASSERT */9899/* Need:100* ZSTD_DEBUG_PRINT()101*/102#ifdef ZSTD_DEPS_NEED_IO103#ifndef ZSTD_DEPS_IO104#define ZSTD_DEPS_IO105106#include <stdio.h>107#define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)108109#endif /* ZSTD_DEPS_IO */110#endif /* ZSTD_DEPS_NEED_IO */111112/* Only requested when <stdint.h> is known to be present.113* Need:114* intptr_t115*/116#ifdef ZSTD_DEPS_NEED_STDINT117#ifndef ZSTD_DEPS_STDINT118#define ZSTD_DEPS_STDINT119120#include <stdint.h>121122#endif /* ZSTD_DEPS_STDINT */123#endif /* ZSTD_DEPS_NEED_STDINT */124125126