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