]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/platform_defs.h.in
include: stop using SIZEOF_LONG
[thirdparty/xfsprogs-dev.git] / include / platform_defs.h.in
1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6 #ifndef __XFS_PLATFORM_DEFS_H__
7 #define __XFS_PLATFORM_DEFS_H__
8
9 #include <stdio.h>
10 #include <errno.h>
11 #include <fcntl.h>
12 #include <stdarg.h>
13 #include <assert.h>
14 #include <stddef.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <stdint.h>
18 #include <unistd.h>
19 #include <pthread.h>
20 #include <ctype.h>
21 #include <sys/types.h>
22 #include <sys/param.h>
23 #include <limits.h>
24 #include <stdbool.h>
25 #include <libgen.h>
26 #include <urcu.h>
27
28 /* long and pointer must be either 32 bit or 64 bit */
29 #define BITS_PER_LONG (sizeof(long) * CHAR_BIT)
30
31 typedef unsigned short umode_t;
32
33 /* Define if you want gettext (I18N) support */
34 #undef ENABLE_GETTEXT
35 #ifdef ENABLE_GETTEXT
36 # include <libintl.h>
37 # define _(x) gettext(x)
38 # define N_(x) x
39 #else
40 # define _(x) (x)
41 # define N_(x) x
42 # define textdomain(d) do { } while (0)
43 # define bindtextdomain(d,dir) do { } while (0)
44 #endif
45 #include <locale.h>
46
47 #define IRIX_DEV_BITSMAJOR 14
48 #define IRIX_DEV_BITSMINOR 18
49 #define IRIX_DEV_MAXMAJ 0x1ff
50 #define IRIX_DEV_MAXMIN 0x3ffff
51 #define IRIX_DEV_MAJOR(dev) ((int)(((unsigned)(dev) >> IRIX_DEV_BITSMINOR) \
52 & IRIX_DEV_MAXMAJ))
53 #define IRIX_DEV_MINOR(dev) ((int)((dev) & IRIX_DEV_MAXMIN))
54 #define IRIX_MKDEV(major,minor) ((xfs_dev_t)(((major) << IRIX_DEV_BITSMINOR) \
55 | (minor&IRIX_DEV_MAXMIN)))
56 #define IRIX_DEV_TO_KDEVT(dev) makedev(IRIX_DEV_MAJOR(dev),IRIX_DEV_MINOR(dev))
57
58 #ifndef min
59 #define min(a,b) (((a)<(b))?(a):(b))
60 #define max(a,b) (((a)>(b))?(a):(b))
61 #endif
62 #define max3(a,b,c) max(max(a, b), c)
63
64 /* If param.h doesn't provide it, i.e. for Android */
65 #ifndef NBBY
66 #define NBBY 8
67 #endif
68
69 #ifdef DEBUG
70 # define ASSERT(EX) assert(EX)
71 #else
72 # define ASSERT(EX) ((void) 0)
73 #endif
74
75 extern int platform_nproc(void);
76
77 #define NSEC_PER_SEC (1000000000ULL)
78 #define NSEC_PER_USEC (1000ULL)
79
80 /* Simplified from version in include/linux/overflow.h */
81
82 /*
83 * Compute a*b+c, returning SIZE_MAX on overflow. Internal helper for
84 * struct_size() below.
85 */
86 static inline size_t __ab_c_size(size_t a, size_t b, size_t c)
87 {
88 return (a * b) + c;
89 }
90
91 #define __must_be_array(a) (0)
92
93 /**
94 * struct_size() - Calculate size of structure with trailing array.
95 * @p: Pointer to the structure.
96 * @member: Name of the array member.
97 * @count: Number of elements in the array.
98 *
99 * Calculates size of memory needed for structure @p followed by an
100 * array of @count number of @member elements.
101 *
102 * Return: number of bytes needed or SIZE_MAX on overflow.
103 */
104 #define struct_size(p, member, count) \
105 __ab_c_size(count, \
106 sizeof(*(p)->member) + __must_be_array((p)->member), \
107 sizeof(*(p)))
108
109 /**
110 * struct_size_t() - Calculate size of structure with trailing flexible array
111 * @type: structure type name.
112 * @member: Name of the array member.
113 * @count: Number of elements in the array.
114 *
115 * Calculates size of memory needed for structure @type followed by an
116 * array of @count number of @member elements. Prefer using struct_size()
117 * when possible instead, to keep calculations associated with a specific
118 * instance variable of type @type.
119 *
120 * Return: number of bytes needed or SIZE_MAX on overflow.
121 */
122 #define struct_size_t(type, member, count) \
123 struct_size((type *)NULL, member, count)
124
125 /*
126 * Add the pseudo keyword 'fallthrough' so case statement blocks
127 * must end with any of these keywords:
128 * break;
129 * fallthrough;
130 * continue;
131 * goto <label>;
132 * return [expression];
133 *
134 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
135 */
136 #if defined __has_attribute
137 # if __has_attribute(__fallthrough__)
138 # define fallthrough __attribute__((__fallthrough__))
139 # else
140 # define fallthrough do {} while (0) /* fallthrough */
141 # endif
142 #else
143 # define fallthrough do {} while (0) /* fallthrough */
144 #endif
145
146 /* Only needed for the kernel. */
147 #define __init
148
149 #ifdef __GNUC__
150 #define __return_address __builtin_return_address(0)
151
152 /*
153 * Return the address of a label. Use barrier() so that the optimizer
154 * won't reorder code to refactor the error jumpouts into a single
155 * return, which throws off the reported address.
156 */
157 #define __this_address ({ __label__ __here; __here: barrier(); &&__here; })
158 /* Optimization barrier */
159
160 /* The "volatile" is due to gcc bugs */
161 #define barrier() __asm__ __volatile__("": : :"memory")
162 #endif
163
164 /* Optimization barrier */
165 #ifndef barrier
166 # define barrier() __memory_barrier()
167 #endif
168
169 #endif /* __XFS_PLATFORM_DEFS_H__ */