2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
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.
10 /* Note : this module is expected to remain private, do not expose it */
12 #ifndef ERROR_H_MODULE
13 #define ERROR_H_MODULE
15 #if defined (__cplusplus)
20 /* ****************************************
22 ******************************************/
23 #include <stddef.h> /* size_t */
24 #include "zstd_errors.h" /* enum list */
27 /* ****************************************
29 ******************************************/
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
37 # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
41 /*-****************************************
42 * Customization (error_public.h)
43 ******************************************/
44 typedef ZSTD_ErrorCode ERR_enum;
45 #define PREFIX(name) ZSTD_error_##name
48 /*-****************************************
49 * Error codes handling
50 ******************************************/
52 # undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
54 #define 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); }
61 /*-****************************************
63 ******************************************/
65 const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
67 ERR_STATIC const char* ERR_getErrorName(size_t code)
69 return ERR_getErrorString(ERR_getErrorCode(code));
72 #if defined (__cplusplus)
76 #endif /* ERROR_H_MODULE */