Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame^] | 1 | /** |
| 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 Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 9 | |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 10 | /* 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) |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
| 19 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 20 | /* **************************************** |
| 21 | * Dependencies |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 22 | ******************************************/ |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 23 | #include <stddef.h> /* size_t */ |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 24 | #include "error_public.h" /* enum list */ |
| 25 | |
| 26 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 27 | /* **************************************** |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 28 | * 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 Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 41 | /*-**************************************** |
Yann Collet | de406ee | 2016-03-20 15:46:10 +0100 | [diff] [blame] | 42 | * Customization (error_public.h) |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 43 | ******************************************/ |
Yann Collet | 982ffc7 | 2016-02-05 02:33:10 +0100 | [diff] [blame] | 44 | typedef ZSTD_ErrorCode ERR_enum; |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 45 | #define PREFIX(name) ZSTD_error_##name |
| 46 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 47 | |
| 48 | /*-**************************************** |
| 49 | * Error codes handling |
| 50 | ******************************************/ |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 51 | #ifdef ERROR |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 52 | # undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */ |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 53 | #endif |
Yann Collet | de406ee | 2016-03-20 15:46:10 +0100 | [diff] [blame] | 54 | #define ERROR(name) ((size_t)-PREFIX(name)) |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 55 | |
| 56 | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
| 57 | |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame] | 58 | 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] | 59 | |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 60 | |
| 61 | /*-**************************************** |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 62 | * Error Strings |
| 63 | ******************************************/ |
| 64 | |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame] | 65 | ERR_STATIC const char* ERR_getErrorString(ERR_enum code) |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 66 | { |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 67 | static const char* notErrorCode = "Unspecified error code"; |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame] | 68 | switch( code ) |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 69 | { |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 70 | case PREFIX(no_error): return "No error detected"; |
| 71 | case PREFIX(GENERIC): return "Error (generic)"; |
| 72 | case PREFIX(prefix_unknown): return "Unknown frame descriptor"; |
Yann Collet | 4bf317d | 2016-08-28 07:43:34 -0700 | [diff] [blame] | 73 | case PREFIX(version_unsupported): return "Version not supported"; |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 74 | case PREFIX(parameter_unknown): return "Unknown parameter type"; |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 75 | case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter"; |
| 76 | case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode"; |
Yann Collet | 21588e3 | 2016-03-30 16:50:44 +0200 | [diff] [blame] | 77 | case PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound"; |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 78 | case PREFIX(init_missing): return "Context should be init first"; |
| 79 | case PREFIX(memory_allocation): return "Allocation error : not enough memory"; |
| 80 | case PREFIX(stage_wrong): return "Operation not authorized at current processing stage"; |
| 81 | case PREFIX(dstSize_tooSmall): return "Destination buffer is too small"; |
| 82 | case PREFIX(srcSize_wrong): return "Src size incorrect"; |
| 83 | case PREFIX(corruption_detected): return "Corrupted block detected"; |
Yann Collet | 8e3a36a | 2016-06-01 00:18:28 +0200 | [diff] [blame] | 84 | case PREFIX(checksum_wrong): return "Restored data doesn't match checksum"; |
Yann Collet | de406ee | 2016-03-20 15:46:10 +0100 | [diff] [blame] | 85 | case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported"; |
| 86 | case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large"; |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 87 | case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small"; |
| 88 | case PREFIX(dictionary_corrupted): return "Dictionary is corrupted"; |
Yann Collet | c46fb92 | 2016-05-29 05:01:04 +0200 | [diff] [blame] | 89 | case PREFIX(dictionary_wrong): return "Dictionary mismatch"; |
Yann Collet | 72bff50 | 2016-02-03 12:06:24 +0100 | [diff] [blame] | 90 | case PREFIX(maxCode): |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame] | 91 | default: return notErrorCode; |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
Yann Collet | c75e4c2 | 2016-05-10 17:47:11 +0200 | [diff] [blame] | 95 | ERR_STATIC const char* ERR_getErrorName(size_t code) |
| 96 | { |
| 97 | return ERR_getErrorString(ERR_getErrorCode(code)); |
| 98 | } |
Yann Collet | 977f1f3 | 2016-01-21 15:38:47 +0100 | [diff] [blame] | 99 | |
| 100 | #if defined (__cplusplus) |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | #endif /* ERROR_H_MODULE */ |