blob: 0d2fa7e34b01459d3f5afa858ae133cfdd9db144 [file] [log] [blame]
Yann Collet32fb4072017-08-18 16:52:05 -07001/*
Yann Collet4ded9e52016-08-30 10:04:33 -07002 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 * All rights reserved.
4 *
Yann Collet32fb4072017-08-18 16:52:05 -07005 * 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).
Yann Collet3128e032017-09-08 00:09:23 -07008 * You may select, at your option, one of the above-listed licenses.
Yann Collet4ded9e52016-08-30 10:04:33 -07009 */
Yann Collet977f1f32016-01-21 15:38:47 +010010
Yann Collet977f1f32016-01-21 15:38:47 +010011/* Note : this module is expected to remain private, do not expose it */
12
13#ifndef ERROR_H_MODULE
14#define ERROR_H_MODULE
15
16#if defined (__cplusplus)
17extern "C" {
18#endif
19
20
Yann Collet72bff502016-02-03 12:06:24 +010021/* ****************************************
22* Dependencies
Yann Collet977f1f32016-01-21 15:38:47 +010023******************************************/
Yann Collet72bff502016-02-03 12:06:24 +010024#include <stddef.h> /* size_t */
Yann Colleta17fd732016-10-11 16:41:09 -070025#include "zstd_errors.h" /* enum list */
Yann Collet977f1f32016-01-21 15:38:47 +010026
27
Yann Collet72bff502016-02-03 12:06:24 +010028/* ****************************************
Yann Collet977f1f32016-01-21 15:38:47 +010029* Compiler-specific
30******************************************/
31#if defined(__GNUC__)
32# define ERR_STATIC static __attribute__((unused))
33#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
34# define ERR_STATIC static inline
35#elif defined(_MSC_VER)
36# define ERR_STATIC static __inline
37#else
38# define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
39#endif
40
41
Yann Collet72bff502016-02-03 12:06:24 +010042/*-****************************************
Yann Colletde406ee2016-03-20 15:46:10 +010043* Customization (error_public.h)
Yann Collet977f1f32016-01-21 15:38:47 +010044******************************************/
Yann Collet982ffc72016-02-05 02:33:10 +010045typedef ZSTD_ErrorCode ERR_enum;
Yann Collet977f1f32016-01-21 15:38:47 +010046#define PREFIX(name) ZSTD_error_##name
47
Yann Collet72bff502016-02-03 12:06:24 +010048
49/*-****************************************
50* Error codes handling
51******************************************/
Nick Terrell9822f972017-08-29 11:54:38 -070052#undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
Nick Terrell7c365eb2017-08-25 17:44:32 -070053#define ERROR(name) ZSTD_ERROR(name)
54#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
Yann Collet977f1f32016-01-21 15:38:47 +010055
56ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
57
Yann Colletc75e4c22016-05-10 17:47:11 +020058ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
Yann Collet977f1f32016-01-21 15:38:47 +010059
Yann Collet72bff502016-02-03 12:06:24 +010060
61/*-****************************************
Yann Collet977f1f32016-01-21 15:38:47 +010062* Error Strings
63******************************************/
64
Yann Colletef2357d2016-10-11 17:24:50 -070065const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
Yann Collet977f1f32016-01-21 15:38:47 +010066
Yann Colletc75e4c22016-05-10 17:47:11 +020067ERR_STATIC const char* ERR_getErrorName(size_t code)
68{
69 return ERR_getErrorString(ERR_getErrorCode(code));
70}
Yann Collet977f1f32016-01-21 15:38:47 +010071
72#if defined (__cplusplus)
73}
74#endif
75
76#endif /* ERROR_H_MODULE */