2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Do not put anything in this file that relies on Autoconf defines, since
12 * we're not guaranteed to have included afsconfig.h before this header file.
13 * This is an installed header file, and afsconfig.h is not.
16 #ifndef OPENAFS_AFS_CONFIG_STDS_H
17 #define OPENAFS_AFS_CONFIG_STDS_H 1
19 #include <afs/param.h>
20 #include <sys/types.h>
22 #define IN /* indicates a parameter is read in */
23 #define OUT /* indicates a parameter is sent out (a ptr) */
24 #define INOUT /* indicates a parameter is read in and sent out (a ptr) */
27 #define MACRO_BEGIN do {
30 #define MACRO_END } while (0)
36 #if defined(__HIGHC__)
38 * keep HC from complaining about the use of "old-style" function definitions
41 pragma Off(Prototype_override_warnings);
42 #endif /* defined(__HIGHC__) */
45 /* Now some types to enhance portability. Always use these on the wire or when
46 * laying out shared structures on disk. */
48 /* Imagine that this worked...
49 #if (sizeof(long) != 4) || (sizeof(short) != 2)
50 #error We require size of long and pointers to be equal
53 #define MAX_AFS_INT32 0x7FFFFFFF
54 #define MIN_AFS_INT32 (-MAX_AFS_INT32 - 1)
55 #define MAX_AFS_UINT32 0xFFFFFFFF
56 #define MAX_AFS_INT64 0x7FFFFFFFFFFFFFFFL
57 #define MIN_AFS_INT64 (-MAX_AFS_INT64 - 1)
58 #define MAX_AFS_UINT64 0xFFFFFFFFFFFFFFFFL
60 typedef short afs_int16;
61 typedef unsigned short afs_uint16;
63 typedef int afs_int32;
64 typedef unsigned int afs_uint32;
65 #if defined(AFS_NT40_ENV) && defined(_MSC_VER)
66 typedef __int64 afs_int64;
67 typedef unsigned __int64 afs_uint64;
69 typedef long long afs_int64;
70 typedef unsigned long long afs_uint64;
72 #define ZeroInt64(a) (a = 0)
73 #define AssignInt64(a, b) *(b) = (a)
74 #define IncInt64(a) (*(a))++
75 #define IncUInt64(a) (*(a))++
76 #define DecInt64(a) (*(a))--
77 #define DecUInt64(a) (*(a))--
78 #define GTInt64(a,b) ((a) > (b))
79 #define GEInt64(a,b) ((a) >= (b))
80 #define LEInt64(a,b) ((a) <= (b))
81 #define LTInt64(a,b) ((a) < (b))
82 #define AddInt64(a,b,c) *(c) = (afs_int64)(a) + (afs_int64)(b)
83 #define AddUInt64(a,b,c) *(c) = (afs_uint64)(a) + (afs_uint64)(b)
84 #define SubtractInt64(a,b,c) *(c) = (afs_int64)(a) - (afs_int64)(b)
85 #define SubtractUInt64(a,b,c) *(c) = (afs_uint64)(a) - (afs_uint64)(b)
86 #define CompareInt64(a,b) (afs_int64)(a) - (afs_int64)(b)
87 #define CompareUInt64(a,b) (afs_uint64)(a) - (afs_uint64)(b)
88 #define NonZeroInt64(a) (a)
89 #define Int64ToInt32(a) (a) & MAX_AFS_UINT32
90 #define FillInt64(t,h,l) (t) = ((afs_int64)(h) << 32) | (l);
91 #define SplitInt64(t,h,l) (h) = ((afs_int64)t) >> 32; (l) = (t) & MAX_AFS_UINT32;
92 #define RoundInt64ToInt32(a) (a > MAX_AFS_UINT32) ? MAX_AFS_UINT32 : a;
93 #define RoundInt64ToInt31(a) (a > MAX_AFS_INT32) ? MAX_AFS_INT32 : a;
94 #else /* AFS_64BIT_ENV */
95 typedef long afs_int32;
96 typedef unsigned long afs_uint32;
102 typedef struct Int64 afs_int64;
108 typedef struct u_Int64 afs_uint64;
109 #define ZeroInt64(a) ((a).high = (a).low = 0)
110 #define AssignInt64(a, b) (b)->high = (a).high; (b)->low = (a).low
111 #define IncInt64(a) ((++((a)->low)) ? 0 : (a)->high++ )
112 #define IncUInt64(a) ((++((a)->low)) ? 0 : (a)->high++ )
113 #define DecInt64(a) (((a)->low)-- ? 0 : (a)->high-- )
114 #define DecUInt64(a) (((a)->low)-- ? 0 : (a)->high-- )
115 #define GTInt64(a,b) (((a).high > (b).high) || (((a).high == (b).high) && ((a).low > (b).low)))
116 #define GEInt64(a,b) (((a).high > (b).high) || (((a).high == (b).high) && ((a).low >= (b).low)))
117 #define LEInt64(a,b) (((a).high < (b).high) || (((a).high == (b).high) && ((a).low <= (b).low)))
118 #define LTInt64(a,b) (((a).high < (b).high) || (((a).high == (b).high) && ((a).low < (b).low)))
119 #define CompareInt64(a,b) (((afs_int32)(a).high - (afs_int32)(b).high) || (((a).high == (b).high) && ((a).low - (b).low)))
120 #define AddInt64(a, b, c) { afs_int64 _a, _b; _a = a; _b = b; (c)->low = _a.low + _b.low; (c)->high = _a.high + _b.high + ((c)->low < _b.low); }
121 #define SubtractInt64(a, b, c) { afs_int64 _a, _b; _a = a; _b = b; (c)->low = _a.low - _b.low; (c)->high = _a.high - _b.high - (_a.low < _b.low); }
122 #define CompareUInt64(a,b) (((afs_uint32)(a).high - (afs_uint32)(b).high) || (((a).high == (b).high) && ((a).low - (b).low)))
123 #define AddUInt64(a, b, c) { afs_uint64 _a, _b; _a = a; _b = b; (c)->low = _a.low + _b.low; (c)->high = _a.high + _b.high + ((c)->low < _b.low); }
124 #define SubtractUInt64(a, b, c) { afs_uint64 _a, _b; _a = a; _b = b; (c)->low = _a.low - _b.low; (c)->high = _a.high - _b.high - (_a.low < _b.low); }
125 #define NonZeroInt64(a) (a).low || (a).high
126 #define Int64ToInt32(a) (a).low
127 #define FillInt64(t,h,l) (t).high = (h); (t).low = (l);
128 #define SplitInt64(t,h,l) (h) = (t).high; (l) = (t).low;
129 #define RoundInt64ToInt32(a) (a.high > 0) ? MAX_AFS_UINT32 : a.low;
130 #define RoundInt64ToInt31(a) (a.high > 0) ? MAX_AFS_INT32 : a.low;
131 #endif /* AFS_64BIT_ENV */
133 /* AFS_64BIT_CLIENT should presently be set only for AFS_64BIT_ENV systems */
135 #ifdef AFS_64BIT_CLIENT
136 typedef afs_int64 afs_size_t;
137 typedef afs_uint64 afs_offs_t;
138 #else /* AFS_64BIT_CLIENT */
139 typedef afs_int32 afs_size_t;
140 typedef afs_uint32 afs_offs_t;
141 #endif /* AFS_64BIT_CLIENT */
143 typedef afs_int64 afs_foff_t;
144 typedef afs_uint64 afs_fsize_t;
145 typedef afs_int64 afs_sfsize_t;
146 #define SplitOffsetOrSize(t,h,l) SplitInt64(t,h,l)
148 /* Maximum integer sizes. Also what is expected by %lld, %llu in
150 #ifdef AFS_64BIT_CLIENT
151 typedef afs_int64 afs_intmax_t;
152 typedef afs_uint64 afs_uintmax_t;
153 #else /* !AFS_64BIT_CLIENT */
154 typedef afs_int32 afs_intmax_t;
155 typedef afs_uint32 afs_uintmax_t;
156 #endif /* !AFS_64BIT_CLIENT */
158 /* you still have to include <netinet/in.h> to make these work */
166 /* Since there is going to be considerable use of 64 bit integers we provide
167 * some assistence in this matter. The hyper type is supposed to be compatible
168 * with the afsHyper type: the same macros will work on both. */
170 #if defined(AFS_64BIT_ENV) && 0
172 typedef unsigned long afs_hyper_t;
174 #define hcmp(a,b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
175 #define hsame(a,b) ((a) == (b))
176 #define hiszero(a) ((a) == 0)
177 #define hfitsin32(a) ((a) & 0xffffffff00000000) == 0)
178 #define hset(a,b) ((a) = (b))
179 #define hzero(a) ((a) = 0)
180 #define hones(a) ((a) = ~((unsigned long)0))
181 #define hget32(i,a) ((i) = (unsigned int)(a))
182 #define hget64(hi,lo,a) ((lo) = ((unsigned int)(a)), (hi) = ((a) & (0xffffffff00000000)))
183 #define hset32(a,i) ((a) = ((unsigned int)(i)))
184 #define hset64(a,hi,lo) ((a) = (((hi) << 32) | (lo)))
185 #define hgetlo(a) ((a) & 0xffffffff)
186 #define hgethi(a) (((unsigned int)(a)) >> 32)
187 #define hadd(a,b) ((a) += (b))
189 #define hadd32(a,b) ((a) += (b))
190 #define hshlft(a,n) ((a)<<(n))
192 #else /* AFS_64BIT_ENV */
194 typedef struct afs_hyper_t { /* unsigned 64 bit integers */
199 #define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
200 ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
201 #define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
202 #define hiszero(a) ((a).low == 0 && (a).high == 0)
203 #define hfitsin32(a) ((a).high == 0)
204 #define hset(a,b) ((a) = (b))
205 #define hzero(a) ((a).low = 0, (a).high = 0)
206 #define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
207 #define hget32(i,a) ((i) = (a).low)
208 #define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
209 #define hset32(a,i) ((a).high = 0, (a).low = (i))
210 #define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))
211 #define hgetlo(a) ((a).low)
212 #define hgethi(a) ((a).high)
213 #define hshlft(a,n) \
214 { /*Shift Left n bits*/ \
215 int s = sizeof((a).low) * 8; /*#bits*/ \
216 if ((n) <= 0) { /*No shift*/ \
217 } else if ((n) >= 2*s) { /*Shift off all bits*/ \
218 (a).high = (a).low = 0; \
219 } else if ((n) < s) { /*Part of low shifted into high*/ \
220 (a).high = ((a).high<<(n)) | (((a).low>>(s-(n))) & (1<<(n))-1); \
221 (a).low = (a).low << (n); \
222 } else if ((n) >= s) { /*All of low shifted into high plus some*/ \
223 (a).high = (a).low << ((n)-s); \
228 /* The algorithm here is to check for two cases that cause a carry. If the top
229 * two bits are different then if the sum has the top bit off then there must
230 * have been a carry. If the top bits are both one then there is always a
231 * carry. We assume 32 bit ints and twos complement arithmetic. */
233 #define SIGN 0x80000000
234 #define hadd32(a,i) \
235 ((void)((((a).low ^ (int)(i)) & SIGN) \
236 ? (((((a).low + (int)(i)) & SIGN) == 0) && (a).high++) \
237 : (((a).low & (int)(i) & SIGN) && (a).high++)), \
240 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
241 #endif /* AFS_64BIT_ENV */
243 #if !defined(KERNEL) || defined(UKERNEL)
245 #define max(a, b) ((a) < (b) ? (b) : (a))
246 #define min(a, b) ((a) > (b) ? (b) : (a))
248 /*#define abs(x) ((x) >= 0 ? (x) : -(x))*/
251 /* minumum length of string to pass to int_to_base64 */
252 typedef char b64_string_t[8];
254 #if defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
255 char *int_to_base64();
258 char *int_to_base64(b64_string_t s, int a);
259 int base64_to_int(char *s);
261 #endif /* AFS_NT40_ENV */
263 * The afsUUID data type is built in to RX
268 afs_uint16 time_hi_and_version;
269 char clock_seq_hi_and_reserved;
273 typedef struct afsUUID afsUUID;
275 /* for now, demand attach fileserver is only support on unix pthreads builds */
276 #if defined(DEMAND_ATTACH_ENABLE) && defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
277 #define AFS_DEMAND_ATTACH_FS 1
280 /* A macro that can be used when printf'ing 64 bit integers, as Unix and
281 * windows use a different format string
284 # define AFS_INT64_FMT "I64d"
285 # define AFS_UINT64_FMT "I64u"
286 # define AFS_PTR_FMT "p"
287 # define AFS_SIZET_FMT "Iu"
289 # define AFS_INT64_FMT "lld"
290 # define AFS_UINT64_FMT "llu"
291 # define AFS_PTR_FMT "p"
292 # ifdef PRINTF_TAKES_Z_LEN
293 # define AFS_SIZET_FMT "zu"
295 # define AFS_SIZET_FMT "lu"
296 # endif /* PRINTF_TAKES_Z_LEN */
297 #endif /* AFS_NT40_ENV */
299 /* Functions to safely cast afs_int32 and afs_uint32 so they can be used in
300 * printf statemements with %ld and %lu
303 #define static_inline __inline static
304 #define hdr_static_inline(x) __inline static x
305 #elif defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV)
306 /* The HPUX compiler can segfault on 'static __inline', so fall back to
307 * just 'static' so we can at least compile */
308 #define static_inline static
309 #define hdr_static_inline(x) static x
310 #elif defined(AFS_AIX_ENV) || defined(AFS_USR_AIX_ENV)
311 #define static_inline static
312 #define hdr_static_inline(x) static x
313 #elif defined(AFS_SGI_ENV) || defined(AFS_USR_SGI_ENV)
314 #define static_inline static
315 #define hdr_static_inline(x) x
316 #elif defined(AFS_NBSD_ENV)
317 #define static_inline static __inline __attribute__((always_inline))
318 #define hdr_static_inline(x) static __inline __attribute__((always_inline)) x
320 #define static_inline static inline
321 #define hdr_static_inline(x) static inline x
324 hdr_static_inline(long) afs_printable_int32_ld(afs_int32 d) { return (long) d; }
326 hdr_static_inline(unsigned long) afs_printable_uint32_lu(afs_uint32 d) { return (unsigned long) d; }
328 #ifdef AFS_64BITUSERPOINTER_ENV
329 #define afs_pointer_to_int(p) ((afs_uint32) (afs_uint64) (p))
330 #define afs_int_to_pointer(i) ((void *) (afs_uint64) (i))
332 #define afs_pointer_to_int(p) ((afs_uint32) (p))
333 #define afs_int_to_pointer(i) ((void *) (i))
336 #if defined(__GNUC__) && __GNUC__ > 2
337 #define AFS_UNUSED __attribute__((unused))
338 #define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
339 #define AFS_NORETURN __attribute__((__noreturn__))
340 #elif defined (__clang__)
341 #define AFS_UNUSED __attribute__((unused))
342 #define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
343 #define AFS_NORETURN __attribute__((__noreturn__))
346 #define AFS_ATTRIBUTE_FORMAT(style,x,y)
350 #endif /* OPENAFS_CONFIG_AFS_STDS_H */