blob: dbb202f45536c1822f2b25b8f4b32d7784ffe9e9 [file] [log] [blame]
Yann Collet977f1f32016-01-21 15:38:47 +01001/* ******************************************************************
2 Error codes and messages
3 Copyright (C) 2013-2016, Yann Collet
4
5 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are
9 met:
10
11 * Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above
14 copyright notice, this list of conditions and the following disclaimer
15 in the documentation and/or other materials provided with the
16 distribution.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 You can contact the author at :
31 - Source repository : https://github.com/Cyan4973/zstd
32****************************************************************** */
33/* Note : this module is expected to remain private, do not expose it */
34
35#ifndef ERROR_H_MODULE
36#define ERROR_H_MODULE
37
38#if defined (__cplusplus)
39extern "C" {
40#endif
41
42
43/* *****************************************
44* Includes
45******************************************/
46#include <stddef.h> /* size_t, ptrdiff_t */
47#include "error_public.h" /* enum list */
48
49
50/* *****************************************
51* Compiler-specific
52******************************************/
53#if defined(__GNUC__)
54# define ERR_STATIC static __attribute__((unused))
55#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
56# define ERR_STATIC static inline
57#elif defined(_MSC_VER)
58# define ERR_STATIC static __inline
59#else
60# define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
61#endif
62
63
64/* *****************************************
65* Error Codes
66******************************************/
67#define PREFIX(name) ZSTD_error_##name
68
69#ifdef ERROR
70# undef ERROR /* reported already defined on VS 2015 by Rich Geldreich */
71#endif
72#define ERROR(name) (size_t)-PREFIX(name)
73
74ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
75
76
77/* *****************************************
78* Error Strings
79******************************************/
80
81ERR_STATIC const char* ERR_getErrorName(size_t code)
82{
83 static const char* codeError = "Unspecified error code";
84 switch( (size_t)-code )
85 {
86 case ZSTD_error_No_Error: return "No error detected";
87 case ZSTD_error_GENERIC: return "Error (generic)";
88 case ZSTD_error_prefix_unknown: return "Unknown frame descriptor";
89 case ZSTD_error_frameParameter_unsupported: return "Unsupported frame parameter";
90 case ZSTD_error_frameParameter_unsupportedBy32bitsImplementation: return "Frame parameter unsupported in 32-bits mode";
91 case ZSTD_error_init_missing: return "Context should be init first";
92 case ZSTD_error_memory_allocation: return "Allocation error : not enough memory";
93 case ZSTD_error_dstSize_tooSmall: return "Destination buffer is too small";
94 case ZSTD_error_srcSize_wrong: return "Src size incorrect";
95 case ZSTD_error_corruption_detected: return "Corrupted block detected";
96 case ZSTD_error_tableLog_tooLarge: return "tableLog requires too much memory";
97 case ZSTD_error_maxSymbolValue_tooLarge: return "Unsupported max possible Symbol Value : too large";
98 case ZSTD_error_maxSymbolValue_tooSmall: return "Specified maxSymbolValue is too small";
99 case ZSTD_error_maxCode:
100 default: return codeError;
101 }
102}
103
104
105#if defined (__cplusplus)
106}
107#endif
108
109#endif /* ERROR_H_MODULE */