2017-08-27 10:05:17 +00:00
|
|
|
/*
|
2020-09-18 19:38:36 +00:00
|
|
|
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
|
2017-06-09 01:43:56 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2017-08-27 10:05:17 +00:00
|
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
* in the COPYING file in the root directory of this source tree).
|
2017-10-26 20:41:47 +00:00
|
|
|
* You may select, at your option, one of the above-listed licenses.
|
2017-06-09 01:43:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Note : this module is expected to remain private, do not expose it */
|
|
|
|
|
|
|
|
#ifndef ERROR_H_MODULE
|
|
|
|
#define ERROR_H_MODULE
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* ****************************************
|
|
|
|
* Dependencies
|
|
|
|
******************************************/
|
2021-01-08 10:21:43 +00:00
|
|
|
#include "zstd_deps.h" /* size_t */
|
2017-06-09 01:43:56 +00:00
|
|
|
#include "zstd_errors.h" /* enum list */
|
|
|
|
|
|
|
|
|
|
|
|
/* ****************************************
|
|
|
|
* Compiler-specific
|
|
|
|
******************************************/
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
# define ERR_STATIC static __attribute__((unused))
|
|
|
|
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
|
|
|
# define ERR_STATIC static inline
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
# define ERR_STATIC static __inline
|
|
|
|
#else
|
|
|
|
# define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* Customization (error_public.h)
|
|
|
|
******************************************/
|
|
|
|
typedef ZSTD_ErrorCode ERR_enum;
|
|
|
|
#define PREFIX(name) ZSTD_error_##name
|
|
|
|
|
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* Error codes handling
|
|
|
|
******************************************/
|
2020-09-18 19:38:36 +00:00
|
|
|
#undef ERROR /* already defined on Visual Studio */
|
2017-10-26 20:41:47 +00:00
|
|
|
#define ERROR(name) ZSTD_ERROR(name)
|
|
|
|
#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
|
2017-06-09 01:43:56 +00:00
|
|
|
|
|
|
|
ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
|
|
|
|
|
|
|
|
ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
|
|
|
|
|
2020-09-18 19:38:36 +00:00
|
|
|
/* check and forward error code */
|
|
|
|
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
|
|
|
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
|
|
|
|
2017-06-09 01:43:56 +00:00
|
|
|
|
|
|
|
/*-****************************************
|
|
|
|
* Error Strings
|
|
|
|
******************************************/
|
|
|
|
|
|
|
|
const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
|
|
|
|
|
|
|
|
ERR_STATIC const char* ERR_getErrorName(size_t code)
|
|
|
|
{
|
|
|
|
return ERR_getErrorString(ERR_getErrorCode(code));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ERROR_H_MODULE */
|