Matteo Scandolo | 9a2772a | 2018-11-19 14:56:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This source code is licensed under both the BSD-style license (found in the |
| 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found |
| 7 | * in the COPYING file in the root directory of this source tree). |
| 8 | * You may select, at your option, one of the above-listed licenses. |
| 9 | */ |
| 10 | |
| 11 | /* Note : this module is expected to remain private, do not expose it */ |
| 12 | |
| 13 | #ifndef ERROR_H_MODULE |
| 14 | #define ERROR_H_MODULE |
| 15 | |
| 16 | #if defined (__cplusplus) |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
| 20 | |
| 21 | /* **************************************** |
| 22 | * Dependencies |
| 23 | ******************************************/ |
| 24 | #include <stddef.h> /* size_t */ |
| 25 | #include "zstd_errors.h" /* enum list */ |
| 26 | |
| 27 | |
| 28 | /* **************************************** |
| 29 | * Compiler-specific |
| 30 | ******************************************/ |
| 31 | #if defined(__GNUC__) |
| 32 | # define ERR_STATIC static __attribute__((unused)) |
| 33 | #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) |
| 34 | # define ERR_STATIC static inline |
| 35 | #elif defined(_MSC_VER) |
| 36 | # define ERR_STATIC static __inline |
| 37 | #else |
| 38 | # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ |
| 39 | #endif |
| 40 | |
| 41 | |
| 42 | /*-**************************************** |
| 43 | * Customization (error_public.h) |
| 44 | ******************************************/ |
| 45 | typedef ZSTD_ErrorCode ERR_enum; |
| 46 | #define PREFIX(name) ZSTD_error_##name |
| 47 | |
| 48 | |
| 49 | /*-**************************************** |
| 50 | * Error codes handling |
| 51 | ******************************************/ |
| 52 | #undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */ |
| 53 | #define ERROR(name) ZSTD_ERROR(name) |
| 54 | #define ZSTD_ERROR(name) ((size_t)-PREFIX(name)) |
| 55 | |
| 56 | ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } |
| 57 | |
| 58 | ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } |
| 59 | |
| 60 | |
| 61 | /*-**************************************** |
| 62 | * Error Strings |
| 63 | ******************************************/ |
| 64 | |
| 65 | const char* ERR_getErrorString(ERR_enum code); /* error_private.c */ |
| 66 | |
| 67 | ERR_STATIC const char* ERR_getErrorName(size_t code) |
| 68 | { |
| 69 | return ERR_getErrorString(ERR_getErrorCode(code)); |
| 70 | } |
| 71 | |
| 72 | #if defined (__cplusplus) |
| 73 | } |
| 74 | #endif |
| 75 | |
| 76 | #endif /* ERROR_H_MODULE */ |