xref: /aosp_15_r20/external/erofs-utils/include/erofs/err.h (revision 33b1fccf6a0fada2c2875d400ed01119b7676ee5)
1 /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
2 /*
3  * Copyright (C) 2018 HUAWEI, Inc.
4  *             http://www.huawei.com/
5  * Created by Li Guifu <[email protected]>
6  */
7 #ifndef __EROFS_ERR_H
8 #define __EROFS_ERR_H
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
15 #include <errno.h>
16 
17 #define MAX_ERRNO (4095)
18 #define IS_ERR_VALUE(x)                                                        \
19 	((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
20 
ERR_PTR(long error)21 static inline void *ERR_PTR(long error)
22 {
23 	return (void *)error;
24 }
25 
IS_ERR(const void * ptr)26 static inline int IS_ERR(const void *ptr)
27 {
28 	return IS_ERR_VALUE((unsigned long)ptr);
29 }
30 
PTR_ERR(const void * ptr)31 static inline long PTR_ERR(const void *ptr)
32 {
33 	return (long) ptr;
34 }
35 
ERR_CAST(const void * ptr)36 static inline void * ERR_CAST(const void *ptr)
37 {
38 	/* cast away the const */
39 	return (void *) ptr;
40 }
41 
42 #ifdef __cplusplus
43 }
44 #endif
45 
46 #endif
47