xref: /openbmc/linux/lib/zstd/common/error_private.h (revision 901181b7)
1 /*
2  * Copyright (c) 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 
17 
18 /* ****************************************
19 *  Dependencies
20 ******************************************/
21 #include "zstd_deps.h"    /* size_t */
22 #include <linux/zstd_errors.h>  /* enum list */
23 
24 
25 /* ****************************************
26 *  Compiler-specific
27 ******************************************/
28 #define ERR_STATIC static __attribute__((unused))
29 
30 
31 /*-****************************************
32 *  Customization (error_public.h)
33 ******************************************/
34 typedef ZSTD_ErrorCode ERR_enum;
35 #define PREFIX(name) ZSTD_error_##name
36 
37 
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))
44 
45 ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
46 
47 ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
48 
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); }
52 
53 
54 /*-****************************************
55 *  Error Strings
56 ******************************************/
57 
58 const char* ERR_getErrorString(ERR_enum code);   /* error_private.c */
59 
60 ERR_STATIC const char* ERR_getErrorName(size_t code)
61 {
62     return ERR_getErrorString(ERR_getErrorCode(code));
63 }
64 
65 
66 #endif /* ERROR_H_MODULE */
67