2 * Copyright (c) Yann Collet, Facebook, Inc.
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.
11 /* Note : this module is expected to remain private, do not expose it */
13 #ifndef ERROR_H_MODULE
14 #define ERROR_H_MODULE
18 /* ****************************************
20 ******************************************/
21 #include "zstd_deps.h" /* size_t */
22 #include <linux/zstd_errors.h> /* enum list */
25 /* ****************************************
27 ******************************************/
28 #define ERR_STATIC static __attribute__((unused))
31 /*-****************************************
32 * Customization (error_public.h)
33 ******************************************/
34 typedef ZSTD_ErrorCode ERR_enum;
35 #define PREFIX(name) ZSTD_error_##name
38 /*-****************************************
39 * Error codes handling
40 ******************************************/
41 #undef ERROR /* already defined on Visual Studio */
42 #define ERROR(name) ZSTD_ERROR(name)
43 #define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
45 ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
47 ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
49 /* check and forward error code */
50 #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
51 #define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
54 /*-****************************************
56 ******************************************/
58 const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
60 ERR_STATIC const char* ERR_getErrorName(size_t code)
62 return ERR_getErrorString(ERR_getErrorCode(code));
66 #endif /* ERROR_H_MODULE */