1 | /* ****************************************************************** |
---|
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 | - Homepage : http://www.zstd.net |
---|
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) |
---|
39 | extern "C" { |
---|
40 | #endif |
---|
41 | |
---|
42 | |
---|
43 | /* **************************************** |
---|
44 | * Dependencies |
---|
45 | ******************************************/ |
---|
46 | #include <stddef.h> /* size_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 | * Customization (error_public.h) |
---|
66 | ******************************************/ |
---|
67 | typedef ZSTD_ErrorCode ERR_enum; |
---|
68 | #define PREFIX(name) ZSTD_error_##name |
---|
69 | |
---|
70 | |
---|
71 | /*-**************************************** |
---|
72 | * Error codes handling |
---|
73 | ******************************************/ |
---|
74 | #ifdef ERROR |
---|
75 | # undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */ |
---|
76 | #endif |
---|
77 | #define ERROR(name) ((size_t)-PREFIX(name)) |
---|
78 | |
---|
79 | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
---|
80 | |
---|
81 | ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } |
---|
82 | |
---|
83 | |
---|
84 | /*-**************************************** |
---|
85 | * Error Strings |
---|
86 | ******************************************/ |
---|
87 | |
---|
88 | ERR_STATIC const char* ERR_getErrorString(ERR_enum code) |
---|
89 | { |
---|
90 | static const char* notErrorCode = "Unspecified error code"; |
---|
91 | switch( code ) |
---|
92 | { |
---|
93 | case PREFIX(no_error): return "No error detected"; |
---|
94 | case PREFIX(GENERIC): return "Error (generic)"; |
---|
95 | case PREFIX(prefix_unknown): return "Unknown frame descriptor"; |
---|
96 | case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter"; |
---|
97 | case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode"; |
---|
98 | case PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound"; |
---|
99 | case PREFIX(init_missing): return "Context should be init first"; |
---|
100 | case PREFIX(memory_allocation): return "Allocation error : not enough memory"; |
---|
101 | case PREFIX(stage_wrong): return "Operation not authorized at current processing stage"; |
---|
102 | case PREFIX(dstSize_tooSmall): return "Destination buffer is too small"; |
---|
103 | case PREFIX(srcSize_wrong): return "Src size incorrect"; |
---|
104 | case PREFIX(corruption_detected): return "Corrupted block detected"; |
---|
105 | case PREFIX(checksum_wrong): return "Restored data doesn't match checksum"; |
---|
106 | case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported"; |
---|
107 | case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large"; |
---|
108 | case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small"; |
---|
109 | case PREFIX(dictionary_corrupted): return "Dictionary is corrupted"; |
---|
110 | case PREFIX(dictionary_wrong): return "Dictionary mismatch"; |
---|
111 | case PREFIX(maxCode): |
---|
112 | default: return notErrorCode; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | ERR_STATIC const char* ERR_getErrorName(size_t code) |
---|
117 | { |
---|
118 | return ERR_getErrorString(ERR_getErrorCode(code)); |
---|
119 | } |
---|
120 | |
---|
121 | #if defined (__cplusplus) |
---|
122 | } |
---|
123 | #endif |
---|
124 | |
---|
125 | #endif /* ERROR_H_MODULE */ |
---|