0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #define ZSTD_DEPS_NEED_MALLOC
0017 #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
0018 #include "error_private.h"
0019 #include "zstd_internal.h"
0020
0021
0022
0023
0024
0025 unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
0026
0027 const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
0028
0029
0030
0031
0032
0033 #undef ZSTD_isError
0034
0035
0036
0037 unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
0038
0039
0040
0041 const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
0042
0043
0044
0045 ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
0046
0047
0048
0049 const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
0050
0051
0052
0053
0054
0055
0056 void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
0057 {
0058 if (customMem.customAlloc)
0059 return customMem.customAlloc(customMem.opaque, size);
0060 return ZSTD_malloc(size);
0061 }
0062
0063 void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
0064 {
0065 if (customMem.customAlloc) {
0066
0067
0068 void* const ptr = customMem.customAlloc(customMem.opaque, size);
0069 ZSTD_memset(ptr, 0, size);
0070 return ptr;
0071 }
0072 return ZSTD_calloc(1, size);
0073 }
0074
0075 void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
0076 {
0077 if (ptr!=NULL) {
0078 if (customMem.customFree)
0079 customMem.customFree(customMem.opaque, ptr);
0080 else
0081 ZSTD_free(ptr);
0082 }
0083 }