Path: blob/master/Utilities/cmzstd/lib/common/zstd_deps.h
3158 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#include <limits.h>27#include <stddef.h>28#include <string.h>2930#if defined(__GNUC__) && __GNUC__ >= 431# define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))32# define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))33# define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))34#else35# define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))36# define ZSTD_memmove(d,s,l) memmove((d),(s),(l))37# define ZSTD_memset(p,v,l) memset((p),(v),(l))38#endif3940#endif /* ZSTD_DEPS_COMMON */4142/* Need:43* ZSTD_malloc()44* ZSTD_free()45* ZSTD_calloc()46*/47#ifdef ZSTD_DEPS_NEED_MALLOC48#ifndef ZSTD_DEPS_MALLOC49#define ZSTD_DEPS_MALLOC5051#include <stdlib.h>5253#define ZSTD_malloc(s) malloc(s)54#define ZSTD_calloc(n,s) calloc((n), (s))55#define ZSTD_free(p) free((p))5657#endif /* ZSTD_DEPS_MALLOC */58#endif /* ZSTD_DEPS_NEED_MALLOC */5960/*61* Provides 64-bit math support.62* Need:63* U64 ZSTD_div64(U64 dividend, U32 divisor)64*/65#ifdef ZSTD_DEPS_NEED_MATH6466#ifndef ZSTD_DEPS_MATH6467#define ZSTD_DEPS_MATH646869#define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))7071#endif /* ZSTD_DEPS_MATH64 */72#endif /* ZSTD_DEPS_NEED_MATH64 */7374/* Need:75* assert()76*/77#ifdef ZSTD_DEPS_NEED_ASSERT78#ifndef ZSTD_DEPS_ASSERT79#define ZSTD_DEPS_ASSERT8081#include <assert.h>8283#endif /* ZSTD_DEPS_ASSERT */84#endif /* ZSTD_DEPS_NEED_ASSERT */8586/* Need:87* ZSTD_DEBUG_PRINT()88*/89#ifdef ZSTD_DEPS_NEED_IO90#ifndef ZSTD_DEPS_IO91#define ZSTD_DEPS_IO9293#include <stdio.h>94#define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)9596#endif /* ZSTD_DEPS_IO */97#endif /* ZSTD_DEPS_NEED_IO */9899/* Only requested when <stdint.h> is known to be present.100* Need:101* intptr_t102*/103#ifdef ZSTD_DEPS_NEED_STDINT104#ifndef ZSTD_DEPS_STDINT105#define ZSTD_DEPS_STDINT106107#include <stdint.h>108109#endif /* ZSTD_DEPS_STDINT */110#endif /* ZSTD_DEPS_NEED_STDINT */111112113