2016-08-30 10:04:33 -07: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 17:14:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-12 15:55:26 +02:00
|
|
|
/*-*************************************
|
2016-04-22 17:14:25 +02:00
|
|
|
* Dependencies
|
|
|
|
***************************************/
|
2016-06-02 13:04:18 +02:00
|
|
|
#include <stdlib.h> /* malloc */
|
2016-04-22 17:14:25 +02:00
|
|
|
#include "error_private.h"
|
2016-06-04 19:47:02 +02:00
|
|
|
#define ZSTD_STATIC_LINKING_ONLY
|
2017-05-16 16:12:23 -07:00
|
|
|
#include "zstd.h"
|
2016-05-12 15:55:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* Version
|
|
|
|
******************************************/
|
|
|
|
unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
|
2016-04-22 17:14:25 +02:00
|
|
|
|
2017-05-16 16:12:23 -07:00
|
|
|
const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
|
|
|
|
|
2016-04-22 17:14:25 +02: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 15:55:26 +02: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 17:14:25 +02:00
|
|
|
/*! ZSTD_getError() :
|
|
|
|
* convert a `size_t` function result into a proper ZSTD_errorCode enum */
|
2016-05-10 17:47:11 +02:00
|
|
|
ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
|
2016-04-22 17:14:25 +02:00
|
|
|
|
2016-05-12 15:55:26 +02:00
|
|
|
/*! ZSTD_getErrorString() :
|
|
|
|
* provides error code string from enum */
|
2017-02-08 15:31:47 -08:00
|
|
|
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
|
2016-05-10 17:47:11 +02:00
|
|
|
|
2016-06-02 13:04:18 +02:00
|
|
|
|
2016-08-28 21:05:43 -07:00
|
|
|
/*=**************************************************************
|
|
|
|
* Custom allocator
|
|
|
|
****************************************************************/
|
|
|
|
/* default uses stdlib */
|
2016-06-02 13:04:18 +02:00
|
|
|
void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
|
|
|
|
{
|
|
|
|
void* address = malloc(size);
|
2016-06-02 15:11:39 +02:00
|
|
|
(void)opaque;
|
2016-06-02 13:04:18 +02:00
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZSTD_defaultFreeFunction(void* opaque, void* address)
|
|
|
|
{
|
|
|
|
(void)opaque;
|
|
|
|
free(address);
|
|
|
|
}
|
2016-08-28 21:05:43 -07: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);
|
|
|
|
}
|