4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2014, Intel Corporation.
24 * Author: John L. Hammond <john.hammond@intel.com>
29 #if defined(__linux__) && defined(__KERNEL__)
30 # include <linux/err.h>
31 #else /* __KERNEL__ */
33 # define IS_ERR_VALUE(x) ((x) >= (unsigned long)-4095)
35 static inline void *ERR_PTR(long error)
40 static inline long PTR_ERR(const void *ptr)
45 static inline long IS_ERR(const void *ptr)
47 return IS_ERR_VALUE((unsigned long)ptr);
50 static inline long IS_ERR_OR_NULL(const void *ptr)
52 return IS_ERR_VALUE((unsigned long)ptr) || ptr == NULL;
56 * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
57 * @ptr: The pointer to cast.
59 * Explicitly cast an error-valued pointer to another pointer type in such a
60 * way as to make it clear that's what's going on.
62 static inline void *ERR_CAST(const void *ptr)
64 /* Cast away the const. */
68 # endif /* !__KERNEL__ */
70 #endif /* LIBCFS_ERR_H_ */