~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/zstd/common/zstd_common.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (c) Yann Collet, Facebook, Inc.
  3  * All rights reserved.
  4  *
  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.
  9  */
 10 
 11 
 12 
 13 /*-*************************************
 14 *  Dependencies
 15 ***************************************/
 16 #define ZSTD_DEPS_NEED_MALLOC
 17 #include "zstd_deps.h"   /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
 18 #include "error_private.h"
 19 #include "zstd_internal.h"
 20 
 21 
 22 /*-****************************************
 23 *  Version
 24 ******************************************/
 25 unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
 26 
 27 const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
 28 
 29 
 30 /*-****************************************
 31 *  ZSTD Error Management
 32 ******************************************/
 33 #undef ZSTD_isError   /* defined within zstd_internal.h */
 34 /*! ZSTD_isError() :
 35  *  tells if a return value is an error code
 36  *  symbol is required for external callers */
 37 unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
 38 
 39 /*! ZSTD_getErrorName() :
 40  *  provides error code string from function result (useful for debugging) */
 41 const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
 42 
 43 /*! ZSTD_getError() :
 44  *  convert a `size_t` function result into a proper ZSTD_errorCode enum */
 45 ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
 46 
 47 /*! ZSTD_getErrorString() :
 48  *  provides error code string from enum */
 49 const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
 50 
 51 
 52 
 53 /*=**************************************************************
 54 *  Custom allocator
 55 ****************************************************************/
 56 void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
 57 {
 58     if (customMem.customAlloc)
 59         return customMem.customAlloc(customMem.opaque, size);
 60     return ZSTD_malloc(size);
 61 }
 62 
 63 void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
 64 {
 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         ZSTD_memset(ptr, 0, size);
 70         return ptr;
 71     }
 72     return ZSTD_calloc(1, size);
 73 }
 74 
 75 void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
 76 {
 77     if (ptr!=NULL) {
 78         if (customMem.customFree)
 79             customMem.customFree(customMem.opaque, ptr);
 80         else
 81             ZSTD_free(ptr);
 82     }
 83 }
 84 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php