2 * Copyright (c) Yann Collet, Facebook, Inc.
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.
13 /*-*************************************
15 ***************************************/
16 #include <linux/module.h>
17 #define ZSTD_DEPS_NEED_MALLOC
18 #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
19 #include "error_private.h"
20 #include "zstd_internal.h"
23 /*-****************************************
25 ******************************************/
26 unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
28 const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
31 /*-****************************************
32 * ZSTD Error Management
33 ******************************************/
34 #undef ZSTD_isError /* defined within zstd_internal.h */
36 * tells if a return value is an error code
37 * symbol is required for external callers */
38 unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
39 EXPORT_SYMBOL_GPL(ZSTD_isError);
41 /*! ZSTD_getErrorName() :
42 * provides error code string from function result (useful for debugging) */
43 const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
44 EXPORT_SYMBOL_GPL(ZSTD_getErrorName);
47 * convert a `size_t` function result into a proper ZSTD_errorCode enum */
48 ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
49 EXPORT_SYMBOL_GPL(ZSTD_getErrorCode);
51 /*! ZSTD_getErrorString() :
52 * provides error code string from enum */
53 const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
57 /*=**************************************************************
59 ****************************************************************/
60 void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
62 if (customMem.customAlloc)
63 return customMem.customAlloc(customMem.opaque, size);
64 return ZSTD_malloc(size);
66 EXPORT_SYMBOL_GPL(ZSTD_customMalloc);
68 void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
70 if (customMem.customAlloc) {
71 /* calloc implemented as malloc+memset;
72 * not as efficient as calloc, but next best guess for custom malloc */
73 void* const ptr = customMem.customAlloc(customMem.opaque, size);
74 ZSTD_memset(ptr, 0, size);
77 return ZSTD_calloc(1, size);
79 EXPORT_SYMBOL_GPL(ZSTD_customCalloc);
81 void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
84 if (customMem.customFree)
85 customMem.customFree(customMem.opaque, ptr);
90 EXPORT_SYMBOL_GPL(ZSTD_customFree);
92 MODULE_LICENSE("Dual BSD/GPL");
93 MODULE_DESCRIPTION("Zstd Common");