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