2016-08-30 17:04:33 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2016-04-22 15:14:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-12 13:55:26 +00:00
|
|
|
/*-*************************************
|
2016-04-22 15:14:25 +00:00
|
|
|
* Dependencies
|
|
|
|
***************************************/
|
2016-06-02 11:04:18 +00:00
|
|
|
#include <stdlib.h> /* malloc */
|
2016-04-22 15:14:25 +00:00
|
|
|
#include "error_private.h"
|
2016-06-04 17:47:02 +00:00
|
|
|
#define ZSTD_STATIC_LINKING_ONLY
|
|
|
|
#include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
|
2016-05-12 13:55:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* Version
|
|
|
|
******************************************/
|
|
|
|
unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
|
2016-04-22 15:14:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* ZSTD Error Management
|
|
|
|
******************************************/
|
|
|
|
/*! ZSTD_isError() :
|
|
|
|
* tells if a return value is an error code */
|
|
|
|
unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
|
|
|
|
|
2016-05-12 13:55:26 +00:00
|
|
|
/*! ZSTD_getErrorName() :
|
|
|
|
* provides error code string from function result (useful for debugging) */
|
|
|
|
const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
|
|
|
|
2016-04-22 15:14:25 +00:00
|
|
|
/*! ZSTD_getError() :
|
|
|
|
* convert a `size_t` function result into a proper ZSTD_errorCode enum */
|
2016-05-10 15:47:11 +00:00
|
|
|
ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
|
2016-04-22 15:14:25 +00:00
|
|
|
|
2016-05-12 13:55:26 +00:00
|
|
|
/*! ZSTD_getErrorString() :
|
|
|
|
* provides error code string from enum */
|
2016-05-10 15:47:11 +00:00
|
|
|
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); }
|
|
|
|
|
2016-06-02 11:04:18 +00:00
|
|
|
|
2016-08-29 04:05:43 +00:00
|
|
|
/*=**************************************************************
|
|
|
|
* Custom allocator
|
|
|
|
****************************************************************/
|
|
|
|
/* default uses stdlib */
|
2016-06-02 11:04:18 +00:00
|
|
|
void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
|
|
|
|
{
|
|
|
|
void* address = malloc(size);
|
2016-06-02 13:11:39 +00:00
|
|
|
(void)opaque;
|
2016-06-02 11:04:18 +00:00
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZSTD_defaultFreeFunction(void* opaque, void* address)
|
|
|
|
{
|
|
|
|
(void)opaque;
|
|
|
|
free(address);
|
|
|
|
}
|
2016-08-29 04:05:43 +00:00
|
|
|
|
|
|
|
void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
|
|
|
|
{
|
|
|
|
return customMem.customAlloc(customMem.opaque, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZSTD_free(void* ptr, ZSTD_customMem customMem)
|
|
|
|
{
|
|
|
|
if (ptr!=NULL)
|
|
|
|
customMem.customFree(customMem.opaque, ptr);
|
|
|
|
}
|