blob: 1bc2e49548187b3a2558682491a6d23b015c3ed0 [file] [log] [blame]
Yann Collet4ded9e52016-08-30 10:04:33 -07001/**
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 */
Yann Collet977f1f32016-01-21 15:38:47 +01009
Yann Collet977f1f32016-01-21 15:38:47 +010010/* Note : this module is expected to remain private, do not expose it */
11
12#ifndef ERROR_H_MODULE
13#define ERROR_H_MODULE
14
15#if defined (__cplusplus)
16extern "C" {
17#endif
18
19
Yann Collet72bff502016-02-03 12:06:24 +010020/* ****************************************
21* Dependencies
Yann Collet977f1f32016-01-21 15:38:47 +010022******************************************/
Yann Collet72bff502016-02-03 12:06:24 +010023#include <stddef.h> /* size_t */
Yann Colleta17fd732016-10-11 16:41:09 -070024#include "zstd_errors.h" /* enum list */
Yann Collet977f1f32016-01-21 15:38:47 +010025
26
Yann Collet72bff502016-02-03 12:06:24 +010027/* ****************************************
Yann Collet977f1f32016-01-21 15:38:47 +010028* Compiler-specific
29******************************************/
30#if defined(__GNUC__)
31# define ERR_STATIC static __attribute__((unused))
32#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
33# define ERR_STATIC static inline
34#elif defined(_MSC_VER)
35# define ERR_STATIC static __inline
36#else
37# define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
38#endif
39
40
Yann Collet72bff502016-02-03 12:06:24 +010041/*-****************************************
Yann Colletde406ee2016-03-20 15:46:10 +010042* Customization (error_public.h)
Yann Collet977f1f32016-01-21 15:38:47 +010043******************************************/
Yann Collet982ffc72016-02-05 02:33:10 +010044typedef ZSTD_ErrorCode ERR_enum;
Yann Collet977f1f32016-01-21 15:38:47 +010045#define PREFIX(name) ZSTD_error_##name
46
Yann Collet72bff502016-02-03 12:06:24 +010047
48/*-****************************************
49* Error codes handling
50******************************************/
Yann Collet977f1f32016-01-21 15:38:47 +010051#ifdef ERROR
Yann Collet72bff502016-02-03 12:06:24 +010052# undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
Yann Collet977f1f32016-01-21 15:38:47 +010053#endif
Yann Colletde406ee2016-03-20 15:46:10 +010054#define 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 */