Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 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 : |
Yann Collet | de406ee | 2016-03-20 15:46:10 +0100 | [diff] [blame] | 31 | - Homepage : http://www.zstd.net |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 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 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 43 | /* **************************************** |
| 44 | * Dependencies |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 45 | ******************************************/ |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 46 | #include <stddef.h> /* size_t */ |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 47 | #include "error_public.h" /* enum list */ |
| 48 | |
| 49 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 50 | /* **************************************** |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 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 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 64 | /*-**************************************** |
Yann Collet | de406ee | 2016-03-20 15:46:10 +0100 | [diff] [blame] | 65 | * Customization (error_public.h) |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 66 | ******************************************/ |
Yann Collet | 982ffc7 | 2016-02-05 02:33:10 +0100 | [diff] [blame] | 67 | typedef ZSTD_ErrorCode ERR_enum; |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 68 | #define PREFIX(name) ZSTD_error_##name |
| 69 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 70 | |
| 71 | /*-**************************************** |
| 72 | * Error codes handling |
| 73 | ******************************************/ |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 74 | #ifdef ERROR |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 75 | # undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */ |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 76 | #endif |
Yann Collet | de406ee | 2016-03-20 15:46:10 +0100 | [diff] [blame] | 77 | #define ERROR(name) ((size_t)-PREFIX(name)) |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 78 | |
| 79 | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
| 80 | |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame^] | 81 | ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 82 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 83 | |
| 84 | /*-**************************************** |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 85 | * Error Strings |
| 86 | ******************************************/ |
| 87 | |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame^] | 88 | ERR_STATIC const char* ERR_getErrorString(ERR_enum code) |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 89 | { |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 90 | static const char* notErrorCode = "Unspecified error code"; |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame^] | 91 | switch( code ) |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 92 | { |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 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"; |
Yann Collet | 21588e3 | 2016-03-30 16:50:44 +0200 | [diff] [blame] | 98 | case PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound"; |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 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"; |
Yann Collet | de406ee | 2016-03-20 15:46:10 +0100 | [diff] [blame] | 105 | case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported"; |
| 106 | case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large"; |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 107 | case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small"; |
| 108 | case PREFIX(dictionary_corrupted): return "Dictionary is corrupted"; |
| 109 | case PREFIX(maxCode): |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame^] | 110 | default: return notErrorCode; |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame^] | 114 | ERR_STATIC const char* ERR_getErrorName(size_t code) |
| 115 | { |
| 116 | return ERR_getErrorString(ERR_getErrorCode(code)); |
| 117 | } |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 118 | |
| 119 | #if defined (__cplusplus) |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | #endif /* ERROR_H_MODULE */ |