Path: blob/master/Utilities/cmzstd/lib/common/zstd_deps.h
5020 views
/*1* Copyright (c) Meta Platforms, Inc. and affiliates.2* All rights reserved.3*4* This source code is licensed under both the BSD-style license (found in the5* LICENSE file in the root directory of this source tree) and the GPLv2 (found6* in the COPYING file in the root directory of this source tree).7* You may select, at your option, one of the above-listed licenses.8*/910/* This file provides common libc dependencies that zstd requires.11* The purpose is to allow replacing this file with a custom implementation12* to compile zstd without libc support.13*/1415/* Need:16* NULL17* INT_MAX18* UINT_MAX19* ZSTD_memcpy()20* ZSTD_memset()21* ZSTD_memmove()22*/23#ifndef ZSTD_DEPS_COMMON24#define ZSTD_DEPS_COMMON2526/* Even though we use qsort_r only for the dictionary builder, the macro27* _GNU_SOURCE has to be declared *before* the inclusion of any standard28* header and the script 'combine.sh' combines the whole zstd source code29* in a single file.30*/31#if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \32defined(__CYGWIN__) || defined(__MSYS__)33#if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */34#define _GNU_SOURCE35#endif36#endif3738#include <limits.h>39#include <stddef.h>40#include <string.h>4142#if defined(__GNUC__) && __GNUC__ >= 443# define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))44# define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))45# define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))46#else47# define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))48# define ZSTD_memmove(d,s,l) memmove((d),(s),(l))49# define ZSTD_memset(p,v,l) memset((p),(v),(l))50#endif5152#endif /* ZSTD_DEPS_COMMON */5354/* Need:55* ZSTD_malloc()56* ZSTD_free()57* ZSTD_calloc()58*/59#ifdef ZSTD_DEPS_NEED_MALLOC60#ifndef ZSTD_DEPS_MALLOC61#define ZSTD_DEPS_MALLOC6263#include <stdlib.h>6465#define ZSTD_malloc(s) malloc(s)66#define ZSTD_calloc(n,s) calloc((n), (s))67#define ZSTD_free(p) free((p))6869#endif /* ZSTD_DEPS_MALLOC */70#endif /* ZSTD_DEPS_NEED_MALLOC */7172/*73* Provides 64-bit math support.74* Need:75* U64 ZSTD_div64(U64 dividend, U32 divisor)76*/77#ifdef ZSTD_DEPS_NEED_MATH6478#ifndef ZSTD_DEPS_MATH6479#define ZSTD_DEPS_MATH648081#define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))8283#endif /* ZSTD_DEPS_MATH64 */84#endif /* ZSTD_DEPS_NEED_MATH64 */8586/* Need:87* assert()88*/89#ifdef ZSTD_DEPS_NEED_ASSERT90#ifndef ZSTD_DEPS_ASSERT91#define ZSTD_DEPS_ASSERT9293#include <assert.h>9495#endif /* ZSTD_DEPS_ASSERT */96#endif /* ZSTD_DEPS_NEED_ASSERT */9798/* Need:99* ZSTD_DEBUG_PRINT()100*/101#ifdef ZSTD_DEPS_NEED_IO102#ifndef ZSTD_DEPS_IO103#define ZSTD_DEPS_IO104105#include <stdio.h>106#define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)107108#endif /* ZSTD_DEPS_IO */109#endif /* ZSTD_DEPS_NEED_IO */110111/* Only requested when <stdint.h> is known to be present.112* Need:113* intptr_t114*/115#ifdef ZSTD_DEPS_NEED_STDINT116#ifndef ZSTD_DEPS_STDINT117#define ZSTD_DEPS_STDINT118119#include <stdint.h>120121#endif /* ZSTD_DEPS_STDINT */122#endif /* ZSTD_DEPS_NEED_STDINT */123124125