You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zstd_common.c 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
  3. * All rights reserved.
  4. *
  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.
  8. */
  9. /*-*************************************
  10. * Dependencies
  11. ***************************************/
  12. #include <stdlib.h> /* malloc */
  13. #include "error_private.h"
  14. #define ZSTD_STATIC_LINKING_ONLY
  15. #include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
  16. #include "zbuff.h" /* declaration of ZBUFF_isError, ZBUFF_getErrorName */
  17. /*-****************************************
  18. * Version
  19. ******************************************/
  20. unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
  21. /*-****************************************
  22. * ZSTD Error Management
  23. ******************************************/
  24. /*! ZSTD_isError() :
  25. * tells if a return value is an error code */
  26. unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
  27. /*! ZSTD_getErrorName() :
  28. * provides error code string from function result (useful for debugging) */
  29. const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
  30. /*! ZSTD_getError() :
  31. * convert a `size_t` function result into a proper ZSTD_errorCode enum */
  32. ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
  33. /*! ZSTD_getErrorString() :
  34. * provides error code string from enum */
  35. const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); }
  36. /* **************************************************************
  37. * ZBUFF Error Management
  38. ****************************************************************/
  39. unsigned ZBUFF_isError(size_t errorCode) { return ERR_isError(errorCode); }
  40. const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); }
  41. /*=**************************************************************
  42. * Custom allocator
  43. ****************************************************************/
  44. /* default uses stdlib */
  45. void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
  46. {
  47. void* address = malloc(size);
  48. (void)opaque;
  49. return address;
  50. }
  51. void ZSTD_defaultFreeFunction(void* opaque, void* address)
  52. {
  53. (void)opaque;
  54. free(address);
  55. }
  56. void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
  57. {
  58. return customMem.customAlloc(customMem.opaque, size);
  59. }
  60. void ZSTD_free(void* ptr, ZSTD_customMem customMem)
  61. {
  62. if (ptr!=NULL)
  63. customMem.customFree(customMem.opaque, ptr);
  64. }