]> git.proxmox.com Git - ceph.git/blame - ceph/src/zstd/lib/common/zstd_common.c
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / zstd / lib / common / zstd_common.c
CommitLineData
11fdf7f2 1/*
f67539c2 2 * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
7c673cae
FG
3 * All rights reserved.
4 *
11fdf7f2
TL
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.
7c673cae
FG
9 */
10
11
12
13/*-*************************************
14* Dependencies
15***************************************/
11fdf7f2
TL
16#include <stdlib.h> /* malloc, calloc, free */
17#include <string.h> /* memset */
7c673cae 18#include "error_private.h"
11fdf7f2 19#include "zstd_internal.h"
7c673cae
FG
20
21
22/*-****************************************
23* Version
24******************************************/
11fdf7f2
TL
25unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
26
27const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
7c673cae
FG
28
29
30/*-****************************************
31* ZSTD Error Management
32******************************************/
9f95a23c 33#undef ZSTD_isError /* defined within zstd_internal.h */
7c673cae 34/*! ZSTD_isError() :
9f95a23c
TL
35 * tells if a return value is an error code
36 * symbol is required for external callers */
7c673cae
FG
37unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
38
39/*! ZSTD_getErrorName() :
9f95a23c 40 * provides error code string from function result (useful for debugging) */
7c673cae
FG
41const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
42
43/*! ZSTD_getError() :
9f95a23c 44 * convert a `size_t` function result into a proper ZSTD_errorCode enum */
7c673cae
FG
45ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
46
47/*! ZSTD_getErrorString() :
9f95a23c 48 * provides error code string from enum */
11fdf7f2 49const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
7c673cae
FG
50
51
9f95a23c 52
7c673cae
FG
53/*=**************************************************************
54* Custom allocator
55****************************************************************/
11fdf7f2 56void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
7c673cae 57{
11fdf7f2
TL
58 if (customMem.customAlloc)
59 return customMem.customAlloc(customMem.opaque, size);
60 return malloc(size);
7c673cae
FG
61}
62
11fdf7f2 63void* ZSTD_calloc(size_t size, ZSTD_customMem customMem)
7c673cae 64{
11fdf7f2
TL
65 if (customMem.customAlloc) {
66 /* calloc implemented as malloc+memset;
67 * not as efficient as calloc, but next best guess for custom malloc */
68 void* const ptr = customMem.customAlloc(customMem.opaque, size);
69 memset(ptr, 0, size);
70 return ptr;
71 }
72 return calloc(1, size);
7c673cae
FG
73}
74
75void ZSTD_free(void* ptr, ZSTD_customMem customMem)
76{
11fdf7f2
TL
77 if (ptr!=NULL) {
78 if (customMem.customFree)
79 customMem.customFree(customMem.opaque, ptr);
80 else
81 free(ptr);
82 }
7c673cae 83}