2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
12 /*-*************************************
14 ***************************************/
15 #include <stdlib.h> /* malloc */
16 #include "error_private.h"
17 #define ZSTD_STATIC_LINKING_ONLY
18 #include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
21 /*-****************************************
23 ******************************************/
24 unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
27 /*-****************************************
28 * ZSTD Error Management
29 ******************************************/
31 * tells if a return value is an error code */
32 unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
34 /*! ZSTD_getErrorName() :
35 * provides error code string from function result (useful for debugging) */
36 const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
39 * convert a `size_t` function result into a proper ZSTD_errorCode enum */
40 ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
42 /*! ZSTD_getErrorString() :
43 * provides error code string from enum */
44 const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
47 /*=**************************************************************
49 ****************************************************************/
50 /* default uses stdlib */
51 void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
53 void* address = malloc(size);
58 void ZSTD_defaultFreeFunction(void* opaque, void* address)
64 void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
66 return customMem.customAlloc(customMem.opaque, size);
69 void ZSTD_free(void* ptr, ZSTD_customMem customMem)
72 customMem.customFree(customMem.opaque, ptr);