Linux-libre 5.4.48-gnu
[librecmc/linux-libre.git] / lib / zstd / error_private.h
1 /**
2  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of https://github.com/facebook/zstd.
7  * An additional grant of patent rights can be found in the PATENTS file in the
8  * same directory.
9  *
10  * This program is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License version 2 as published by the
12  * Free Software Foundation. This program is dual-licensed; you may select
13  * either version 2 of the GNU General Public License ("GPL") or BSD license
14  * ("BSD").
15  */
16
17 /* Note : this module is expected to remain private, do not expose it */
18
19 #ifndef ERROR_H_MODULE
20 #define ERROR_H_MODULE
21
22 /* ****************************************
23 *  Dependencies
24 ******************************************/
25 #include <linux/types.h> /* size_t */
26 #include <linux/zstd.h>  /* enum list */
27
28 /* ****************************************
29 *  Compiler-specific
30 ******************************************/
31 #define ERR_STATIC static __attribute__((unused))
32
33 /*-****************************************
34 *  Customization (error_public.h)
35 ******************************************/
36 typedef ZSTD_ErrorCode ERR_enum;
37 #define PREFIX(name) ZSTD_error_##name
38
39 /*-****************************************
40 *  Error codes handling
41 ******************************************/
42 #define ERROR(name) ((size_t)-PREFIX(name))
43
44 ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
45
46 ERR_STATIC ERR_enum ERR_getErrorCode(size_t code)
47 {
48         if (!ERR_isError(code))
49                 return (ERR_enum)0;
50         return (ERR_enum)(0 - code);
51 }
52
53 #endif /* ERROR_H_MODULE */