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;
62 typedef int afs_int32;
63 typedef unsigned int afs_uint32;
64 #if defined(AFS_NT40_ENV) && defined(_MSC_VER)
65 typedef __int64 afs_int64;
66 typedef unsigned __int64 afs_uint64;
68 typedef long long afs_int64;
69 typedef unsigned long long afs_uint64;
71 #define ZeroInt64(a) (a = 0)
72 #define AssignInt64(a, b) *(b) = (a)
73 #define IncInt64(a) (*(a))++
74 #define IncUInt64(a) (*(a))++
75 #define DecInt64(a) (*(a))--
76 #define DecUInt64(a) (*(a))--
77 #define GTInt64(a,b) ((a) > (b))
78 #define GEInt64(a,b) ((a) >= (b))
79 #define LEInt64(a,b) ((a) <= (b))
80 #define LTInt64(a,b) ((a) < (b))
81 #define AddInt64(a,b,c) *(c) = (afs_int64)(a) + (afs_int64)(b)
82 #define AddUInt64(a,b,c) *(c) = (afs_uint64)(a) + (afs_uint64)(b)
83 #define SubtractInt64(a,b,c) *(c) = (afs_int64)(a) - (afs_int64)(b)
84 #define SubtractUInt64(a,b,c) *(c) = (afs_uint64)(a) - (afs_uint64)(b)
85 #define CompareInt64(a,b) (afs_int64)(a) - (afs_int64)(b)
86 #define CompareUInt64(a,b) (afs_uint64)(a) - (afs_uint64)(b)
87 #define NonZeroInt64(a) (a)
88 #define Int64ToInt32(a) (a) & MAX_AFS_UINT32
89 #define FillInt64(t,h,l) (t) = ((afs_int64)(h) << 32) | (l);
90 #define SplitInt64(t,h,l) (h) = ((afs_int64)t) >> 32; (l) = (t) & MAX_AFS_UINT32;
91 #define RoundInt64ToInt32(a) (a > MAX_AFS_UINT32) ? MAX_AFS_UINT32 : a;
92 #define RoundInt64ToInt31(a) (a > MAX_AFS_INT32) ? MAX_AFS_INT32 : a;
94 #ifdef AFS_64BIT_CLIENT
95 typedef afs_int64 afs_size_t;
96 typedef afs_uint64 afs_offs_t;
97 #else /* AFS_64BIT_CLIENT */
98 typedef afs_int32 afs_size_t;
99 typedef afs_uint32 afs_offs_t;
100 #endif /* AFS_64BIT_CLIENT */
102 typedef afs_int64 afs_foff_t;
103 typedef afs_uint64 afs_fsize_t;
104 typedef afs_int64 afs_sfsize_t;
105 #define SplitOffsetOrSize(t,h,l) SplitInt64(t,h,l)
107 /* Maximum integer sizes. Also what is expected by %lld, %llu in
109 #ifdef AFS_64BIT_CLIENT
110 typedef afs_int64 afs_intmax_t;
111 typedef afs_uint64 afs_uintmax_t;
112 #else /* !AFS_64BIT_CLIENT */
113 typedef afs_int32 afs_intmax_t;
114 typedef afs_uint32 afs_uintmax_t;
115 #endif /* !AFS_64BIT_CLIENT */
117 /* you still have to include <netinet/in.h> to make these work */
125 /* Since there is going to be considerable use of 64 bit integers we provide
126 * some assistence in this matter. The hyper type is supposed to be compatible
127 * with the afsHyper type: the same macros will work on both. */
131 typedef unsigned long afs_hyper_t;
133 #define hcmp(a,b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
134 #define hsame(a,b) ((a) == (b))
135 #define hiszero(a) ((a) == 0)
136 #define hfitsin32(a) ((a) & 0xffffffff00000000) == 0)
137 #define hset(a,b) ((a) = (b))
138 #define hzero(a) ((a) = 0)
139 #define hones(a) ((a) = ~((unsigned long)0))
140 #define hget32(i,a) ((i) = (unsigned int)(a))
141 #define hget64(hi,lo,a) ((lo) = ((unsigned int)(a)), (hi) = ((a) & (0xffffffff00000000)))
142 #define hset32(a,i) ((a) = ((unsigned int)(i)))
143 #define hset64(a,hi,lo) ((a) = (((hi) << 32) | (lo)))
144 #define hgetlo(a) ((a) & 0xffffffff)
145 #define hgethi(a) (((unsigned int)(a)) >> 32)
146 #define hadd(a,b) ((a) += (b))
148 #define hadd32(a,b) ((a) += (b))
149 #define hshlft(a,n) ((a)<<(n))
153 typedef struct afs_hyper_t { /* unsigned 64 bit integers */
158 #define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
159 ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
160 #define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
161 #define hiszero(a) ((a).low == 0 && (a).high == 0)
162 #define hfitsin32(a) ((a).high == 0)
163 #define hset(a,b) ((a) = (b))
164 #define hzero(a) ((a).low = 0, (a).high = 0)
165 #define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
166 #define hget32(i,a) ((i) = (a).low)
167 #define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
168 #define hset32(a,i) ((a).high = 0, (a).low = (i))
169 #define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))
170 #define hgetlo(a) ((a).low)
171 #define hgethi(a) ((a).high)
172 #define hshlft(a,n) \
173 { /*Shift Left n bits*/ \
174 int s = sizeof((a).low) * 8; /*#bits*/ \
175 if ((n) <= 0) { /*No shift*/ \
176 } else if ((n) >= 2*s) { /*Shift off all bits*/ \
177 (a).high = (a).low = 0; \
178 } else if ((n) < s) { /*Part of low shifted into high*/ \
179 (a).high = ((a).high<<(n)) | (((a).low>>(s-(n))) & (1<<(n))-1); \
180 (a).low = (a).low << (n); \
181 } else if ((n) >= s) { /*All of low shifted into high plus some*/ \
182 (a).high = (a).low << ((n)-s); \
187 /* The algorithm here is to check for two cases that cause a carry. If the top
188 * two bits are different then if the sum has the top bit off then there must
189 * have been a carry. If the top bits are both one then there is always a
190 * carry. We assume 32 bit ints and twos complement arithmetic. */
192 #define SIGN 0x80000000
193 #define hadd32(a,i) \
194 ((void)((((a).low ^ (int)(i)) & SIGN) \
195 ? (((((a).low + (int)(i)) & SIGN) == 0) && (a).high++) \
196 : (((a).low & (int)(i) & SIGN) && (a).high++)), \
199 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
202 #if !defined(KERNEL) || defined(UKERNEL)
204 #define max(a, b) ((a) < (b) ? (b) : (a))
205 #define min(a, b) ((a) > (b) ? (b) : (a))
207 /*#define abs(x) ((x) >= 0 ? (x) : -(x))*/
210 /* minumum length of string to pass to int_to_base64 */
211 typedef char b64_string_t[8];
213 #if defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
214 char *int_to_base64();
217 char *int_to_base64(b64_string_t s, int a);
218 int base64_to_int(char *s);
220 #endif /* AFS_NT40_ENV */
222 * The afsUUID data type is built in to RX
227 afs_uint16 time_hi_and_version;
228 char clock_seq_hi_and_reserved;
232 typedef struct afsUUID afsUUID;
234 /* for now, demand attach fileserver is only support on unix pthreads builds */
235 #if defined(DEMAND_ATTACH_ENABLE) && defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
236 #define AFS_DEMAND_ATTACH_FS 1
239 /* A macro that can be used when printf'ing 64 bit integers, as Unix and
240 * windows use a different format string
243 # define AFS_INT64_FMT "I64d"
244 # define AFS_UINT64_FMT "I64u"
245 # define AFS_PTR_FMT "p"
246 # define AFS_SIZET_FMT "Iu"
248 # define AFS_INT64_FMT "lld"
249 # define AFS_UINT64_FMT "llu"
250 # define AFS_PTR_FMT "p"
251 # ifdef PRINTF_TAKES_Z_LEN
252 # define AFS_SIZET_FMT "zu"
254 # define AFS_SIZET_FMT "lu"
255 # endif /* PRINTF_TAKES_Z_LEN */
256 #endif /* AFS_NT40_ENV */
258 /* Functions to safely cast afs_int32 and afs_uint32 so they can be used in
259 * printf statemements with %ld and %lu
262 #define static_inline __inline static
263 #define hdr_static_inline(x) __inline static x
264 #elif defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV)
265 /* The HPUX compiler can segfault on 'static __inline', so fall back to
266 * just 'static' so we can at least compile */
267 #define static_inline static
268 #define hdr_static_inline(x) static x
269 #elif defined(AFS_AIX_ENV) || defined(AFS_USR_AIX_ENV)
270 #define static_inline static
271 #define hdr_static_inline(x) static x
272 #elif defined(AFS_SGI_ENV) || defined(AFS_USR_SGI_ENV)
273 #define static_inline static
274 #define hdr_static_inline(x) x
275 #elif defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV)
276 #define static_inline static __inline __attribute__((always_inline))
277 #define hdr_static_inline(x) static __inline __attribute__((always_inline)) x
279 #define static_inline static inline
280 #define hdr_static_inline(x) static inline x
283 hdr_static_inline(long) afs_printable_int32_ld(afs_int32 d) { return (long) d; }
285 hdr_static_inline(unsigned long) afs_printable_uint32_lu(afs_uint32 d) { return (unsigned long) d; }
287 #ifdef AFS_64BITUSERPOINTER_ENV
288 #define afs_pointer_to_int(p) ((afs_uint32) (afs_uint64) (p))
289 #define afs_int_to_pointer(i) ((void *) (afs_uint64) (i))
291 #define afs_pointer_to_int(p) ((afs_uint32) (p))
292 #define afs_int_to_pointer(i) ((void *) (i))
295 #if defined(__GNUC__) && __GNUC__ > 2
296 #define AFS_UNUSED __attribute__((unused))
297 #define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
298 #define AFS_NORETURN __attribute__((__noreturn__))
299 #elif defined (__clang__)
300 #define AFS_UNUSED __attribute__((unused))
301 #define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
302 #define AFS_NORETURN __attribute__((__noreturn__))
305 #define AFS_ATTRIBUTE_FORMAT(style,x,y)
309 #endif /* OPENAFS_CONFIG_AFS_STDS_H */