zpool/zfs: restore -V & --version options
[zfs.git] / module / zstd / lib / common / error_private.h
blob982cf8e9fe6f8c44ca22f7f82654a6af03a11738
1 /*
2 * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3 * All rights reserved.
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 */
11 /* Note : this module is expected to remain private, do not expose it */
13 #ifndef ERROR_H_MODULE
14 #define ERROR_H_MODULE
16 #if defined (__cplusplus)
17 extern "C" {
18 #endif
21 /* ****************************************
22 * Dependencies
23 ******************************************/
24 #include <stddef.h> /* size_t */
25 #include "zstd_errors.h" /* enum list */
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
42 /*-****************************************
43 * Customization (error_public.h)
44 ******************************************/
45 typedef ZSTD_ErrorCode ERR_enum;
46 #define PREFIX(name) ZSTD_error_##name
49 /*-****************************************
50 * Error codes handling
51 ******************************************/
52 #undef ERROR /* already defined on Visual Studio */
53 #define ERROR(name) ZSTD_ERROR(name)
54 #define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
56 ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
58 ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
60 /* check and forward error code */
61 #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
62 #define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
65 /*-****************************************
66 * Error Strings
67 ******************************************/
69 const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
71 ERR_STATIC const char* ERR_getErrorName(size_t code)
73 return ERR_getErrorString(ERR_getErrorCode(code));
76 #if defined (__cplusplus)
78 #endif
80 #endif /* ERROR_H_MODULE */