Whamcloud - gitweb
LU-5327 libcfs: add libcfs/types.h
[fs/lustre-release.git] / libcfs / include / libcfs / types.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2014, Intel Corporation.
27  */
28 #ifndef _LIBCFS_TYPES_H
29 #define _LIBCFS_TYPES_H
30
31 #include <linux/types.h>
32
33 #ifndef __KERNEL__
34 # include <limits.h> /* LONG_MAX */
35 # include <stdbool.h> /* bool */
36 #endif /* !__KERNEL__ */
37
38 #if defined(_ASM_GENERIC_INT_L64_H)
39 # define LPF64 "l"
40 #elif defined(_ASM_GENERIC_INT_LL64_H)
41 # define LPF64 "ll"
42 #elif !defined(LPF64)
43 # error "cannot define LPF64"
44 #endif /* !LPF64 */
45
46 #define LPU64 "%"LPF64"u"
47 #define LPD64 "%"LPF64"d"
48 #define LPX64 "%#"LPF64"x"
49 #define LPX64i "%"LPF64"x"
50 #define LPO64 "%#"LPF64"o"
51
52 #define LPLU "%lu"
53 #define LPLD "%ld"
54 #define LPLX "%#lx"
55 #define LPPID "%d"
56
57 #ifndef BITS_PER_LONG
58 # if LONG_MAX == 9223372036854775807
59 #  define BITS_PER_LONG 64
60 # elif LONG_MAX == 2147483647
61 #  define BITS_PER_LONG 32
62 # else /* LONG_MAX == 2147483647 */
63 #  error "cannot define BITS_PER_LONG"
64 # endif /* LONG_MAX != 2147483647 */
65 #endif /* !BITS_PER_LONG */
66
67 #if BITS_PER_LONG == 64
68 # define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
69 # define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
70 # define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
71 #elif BITS_PER_LONG == 32
72 # define LI_POISON ((int)0x5a5a5a5a)
73 # define LL_POISON ((long)0x5a5a5a5a)
74 # define LP_POISON ((void *)(long)0x5a5a5a5a)
75 #else /* BITS_PER_LONG == 32 */
76 # error "cannot define L{I,L,P}_POISON"
77 #endif /* BITS_PER_LONG != 32 */
78
79 typedef unsigned long ulong_ptr_t;
80 typedef long long_ptr_t;
81
82 #endif /* _LIBCFS_TYPES_H */