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
10 #ifndef OPENAFS_AFS_CONFIG_STDS_H
11 #define OPENAFS_AFS_CONFIG_STDS_H 1
13 #include <afs/param.h>
14 #include <sys/types.h>
16 #define IN /* indicates a parameter is read in */
17 #define OUT /* indicates a parameter is sent out (a ptr) */
18 #define INOUT /* indicates a parameter is read in and sent out (a ptr) */
21 #define MACRO_BEGIN do {
24 #define MACRO_END } while (0)
30 #if defined(__HIGHC__)
32 * keep HC from complaining about the use of "old-style" function definitions
35 pragma Off(Prototype_override_warnings);
36 #endif /* defined(__HIGHC__) */
39 /* Now some types to enhance portability. Always use these on the wire or when
40 * laying out shared structures on disk. */
42 /* Imagine that this worked...
43 #if (sizeof(long) != 4) || (sizeof(short) != 2)
44 #error We require size of long and pointers to be equal
47 #define MAX_AFS_INT32 0x7FFFFFFF
48 #define MAX_AFS_UINT32 0xFFFFFFFF
49 #define MAX_AFS_INT64 0x7FFFFFFFFFFFFFFFL
50 #define MAX_AFS_UINT64 0xFFFFFFFFFFFFFFFFL
52 typedef short afs_int16;
53 typedef unsigned short afs_uint16;
55 typedef int afs_int32;
56 typedef unsigned int afs_uint32;
57 #if defined(AFS_NT40_ENV) && defined(_MSC_VER)
58 typedef __int64 afs_int64;
59 typedef unsigned __int64 afs_uint64;
61 typedef long long afs_int64;
62 typedef unsigned long long afs_uint64;
64 #define ZeroInt64(a) (a = 0)
65 #define AssignInt64(a, b) *(b) = (a)
66 #define IncInt64(a) (*(a))++
67 #define IncUInt64(a) (*(a))++
68 #define DecInt64(a) (*(a))--
69 #define DecUInt64(a) (*(a))--
70 #define GTInt64(a,b) ((a) > (b))
71 #define GEInt64(a,b) ((a) >= (b))
72 #define LEInt64(a,b) ((a) <= (b))
73 #define LTInt64(a,b) ((a) < (b))
74 #define AddInt64(a,b,c) *(c) = (afs_int64)(a) + (afs_int64)(b)
75 #define AddUInt64(a,b,c) *(c) = (afs_uint64)(a) + (afs_uint64)(b)
76 #define SubtractInt64(a,b,c) *(c) = (afs_int64)(a) - (afs_int64)(b)
77 #define SubtractUInt64(a,b,c) *(c) = (afs_uint64)(a) - (afs_uint64)(b)
78 #define CompareInt64(a,b) (afs_int64)(a) - (afs_int64)(b)
79 #define CompareUInt64(a,b) (afs_uint64)(a) - (afs_uint64)(b)
80 #define NonZeroInt64(a) (a)
81 #define Int64ToInt32(a) (a) & MAX_AFS_UINT32
82 #define FillInt64(t,h,l) (t) = ((afs_int64)(h) << 32) | (l);
83 #define SplitInt64(t,h,l) (h) = ((afs_int64)t) >> 32; (l) = (t) & MAX_AFS_UINT32;
84 #define RoundInt64ToInt32(a) (a > MAX_AFS_UINT32) ? MAX_AFS_UINT32 : a;
85 #define RoundInt64ToInt31(a) (a > MAX_AFS_INT32) ? MAX_AFS_INT32 : a;
86 #else /* AFS_64BIT_ENV */
87 typedef long afs_int32;
88 typedef unsigned long afs_uint32;
94 typedef struct Int64 afs_int64;
100 typedef struct u_Int64 afs_uint64;
101 #define ZeroInt64(a) ((a).high = (a).low = 0)
102 #define AssignInt64(a, b) (b)->high = (a).high; (b)->low = (a).low
103 #define IncInt64(a) ((++((a)->low)) ? 0 : (a)->high++ )
104 #define IncUInt64(a) ((++((a)->low)) ? 0 : (a)->high++ )
105 #define DecInt64(a) (((a)->low)-- ? 0 : (a)->high-- )
106 #define DecUInt64(a) (((a)->low)-- ? 0 : (a)->high-- )
107 #define GTInt64(a,b) (((a).high > (b).high) || (((a).high == (b).high) && ((a).low > (b).low)))
108 #define GEInt64(a,b) (((a).high > (b).high) || (((a).high == (b).high) && ((a).low >= (b).low)))
109 #define LEInt64(a,b) (((a).high < (b).high) || (((a).high == (b).high) && ((a).low <= (b).low)))
110 #define LTInt64(a,b) (((a).high < (b).high) || (((a).high == (b).high) && ((a).low < (b).low)))
111 #define CompareInt64(a,b) (((afs_int32)(a).high - (afs_int32)(b).high) || (((a).high == (b).high) && ((a).low - (b).low)))
112 #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); }
113 #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); }
114 #define CompareUInt64(a,b) (((afs_uint32)(a).high - (afs_uint32)(b).high) || (((a).high == (b).high) && ((a).low - (b).low)))
115 #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); }
116 #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); }
117 #define NonZeroInt64(a) (a).low || (a).high
118 #define Int64ToInt32(a) (a).low
119 #define FillInt64(t,h,l) (t).high = (h); (t).low = (l);
120 #define SplitInt64(t,h,l) (h) = (t).high; (l) = (t).low;
121 #define RoundInt64ToInt32(a) (a.high > 0) ? MAX_AFS_UINT32 : a.low;
122 #define RoundInt64ToInt31(a) (a.high > 0) ? MAX_AFS_INT32 : a.low;
123 #endif /* AFS_64BIT_ENV */
125 /* AFS_64BIT_CLIENT should presently be set only for AFS_64BIT_ENV systems */
127 #ifdef AFS_64BIT_CLIENT
128 typedef afs_int64 afs_size_t;
129 typedef afs_uint64 afs_offs_t;
130 #else /* AFS_64BIT_CLIENT */
131 typedef afs_int32 afs_size_t;
132 typedef afs_uint32 afs_offs_t;
133 #endif /* AFS_64BIT_CLIENT */
135 #ifdef AFS_LARGEFILE_ENV
136 typedef afs_int64 afs_foff_t;
137 typedef afs_uint64 afs_fsize_t;
138 typedef afs_int64 afs_sfsize_t;
139 #define SplitOffsetOrSize(t,h,l) SplitInt64(t,h,l)
140 #else /* !AFS_LARGEFILE_ENV */
141 typedef afs_int32 afs_foff_t;
142 typedef afs_uint32 afs_fsize_t;
143 typedef afs_int32 afs_sfsize_t;
144 #define SplitOffsetOrSize(t,h,l) (h) = 0; (l) = (t);
145 #endif /* !AFS_LARGEFILE_ENV */
147 /* Maximum integer sizes. Also what is expected by %lld, %llu in
149 #ifdef AFS_64BIT_CLIENT
150 typedef afs_int64 afs_intmax_t;
151 typedef afs_uint64 afs_uintmax_t;
152 #else /* !AFS_64BIT_CLIENT */
153 typedef afs_int32 afs_intmax_t;
154 typedef afs_uint32 afs_uintmax_t;
155 #endif /* !AFS_64BIT_CLIENT */
157 /* you still have to include <netinet/in.h> to make these work */
165 /* Since there is going to be considerable use of 64 bit integers we provide
166 * some assistence in this matter. The hyper type is supposed to be compatible
167 * with the afsHyper type: the same macros will work on both. */
169 #if defined(AFS_64BIT_ENV) && 0
171 typedef unsigned long afs_hyper_t;
173 #define hcmp(a,b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
174 #define hsame(a,b) ((a) == (b))
175 #define hiszero(a) ((a) == 0)
176 #define hfitsin32(a) ((a) & 0xffffffff00000000) == 0)
177 #define hset(a,b) ((a) = (b))
178 #define hzero(a) ((a) = 0)
179 #define hones(a) ((a) = ~((unsigned long)0))
180 #define hget32(i,a) ((i) = (unsigned int)(a))
181 #define hget64(hi,lo,a) ((lo) = ((unsigned int)(a)), (hi) = ((a) & (0xffffffff00000000)))
182 #define hset32(a,i) ((a) = ((unsigned int)(i)))
183 #define hset64(a,hi,lo) ((a) = (((hi) << 32) | (lo)))
184 #define hgetlo(a) ((a) & 0xffffffff)
185 #define hgethi(a) (((unsigned int)(a)) >> 32)
186 #define hadd(a,b) ((a) += (b))
188 #define hadd32(a,b) ((a) += (b))
189 #define hshlft(a,n) ((a)<<(n))
191 #else /* AFS_64BIT_ENV */
193 typedef struct afs_hyper_t { /* unsigned 64 bit integers */
198 #define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
199 ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
200 #define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
201 #define hiszero(a) ((a).low == 0 && (a).high == 0)
202 #define hfitsin32(a) ((a).high == 0)
203 #define hset(a,b) ((a) = (b))
204 #define hzero(a) ((a).low = 0, (a).high = 0)
205 #define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
206 #define hget32(i,a) ((i) = (a).low)
207 #define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
208 #define hset32(a,i) ((a).high = 0, (a).low = (i))
209 #define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))
210 #define hgetlo(a) ((a).low)
211 #define hgethi(a) ((a).high)
212 #define hshlft(a,n) \
213 { /*Shift Left n bits*/ \
214 int s = sizeof((a).low) * 8; /*#bits*/ \
215 if ((n) <= 0) { /*No shift*/ \
216 } else if ((n) >= 2*s) { /*Shift off all bits*/ \
217 (a).high = (a).low = 0; \
218 } else if ((n) < s) { /*Part of low shifted into high*/ \
219 (a).high = ((a).high<<(n)) | (((a).low>>(s-(n))) & (1<<(n))-1); \
220 (a).low = (a).low << (n); \
221 } else if ((n) >= s) { /*All of low shifted into high plus some*/ \
222 (a).high = (a).low << ((n)-s); \
227 /* The algorithm here is to check for two cases that cause a carry. If the top
228 * two bits are different then if the sum has the top bit off then there must
229 * have been a carry. If the top bits are both one then there is always a
230 * carry. We assume 32 bit ints and twos complement arithmetic. */
232 #define SIGN 0x80000000
233 #define hadd32(a,i) \
234 ((void)((((a).low ^ (int)(i)) & SIGN) \
235 ? (((((a).low + (int)(i)) & SIGN) == 0) && (a).high++) \
236 : (((a).low & (int)(i) & SIGN) && (a).high++)), \
239 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
240 #endif /* AFS_64BIT_ENV */
244 #define max(a, b) ((a) < (b) ? (b) : (a))
245 #define min(a, b) ((a) > (b) ? (b) : (a))
247 /*#define abs(x) ((x) >= 0 ? (x) : -(x))*/
250 /* minumum length of string to pass to int_to_base64 */
251 typedef char b64_string_t[8];
253 #if defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
254 char *int_to_base64();
257 char *int_to_base64(b64_string_t s, int a);
258 int base64_to_int(char *s);
260 #endif /* AFS_NT40_ENV */
262 * The afsUUID data type is built in to RX
267 afs_uint16 time_hi_and_version;
268 char clock_seq_hi_and_reserved;
272 typedef struct afsUUID afsUUID;
274 /* for now, demand attach fileserver is only support on unix pthreads builds */
275 #if defined(DEMAND_ATTACH_ENABLE) && defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
276 #define AFS_DEMAND_ATTACH_FS 1
279 /* A macro that can be used when printf'ing 64 bit integers, as Unix and
280 * windows use a different format string
283 #define AFS_INT64_FMT "l64d"
284 #define AFS_PTR_FMT "p"
286 #define AFS_INT64_FMT "lld"
287 #define AFS_PTR_FMT "x"
290 /* Functions to safely cast afs_int32 and afs_uint32 so they can be used in
291 * printf statemements with %ld and %lu
294 #define static_inline __inline static
295 #define hdr_static_inline(x) __inline static x
296 #elif defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV)
297 #define static_inline static __inline
298 #define hdr_static_inline(x) static __inline x
299 #elif defined(AFS_AIX_ENV) || defined(AFS_USR_AIX_ENV)
300 #define static_inline static
301 #define hdr_static_inline(x) static x
302 #elif defined(AFS_SGI_ENV) || defined(AFS_USR_SGI_ENV)
303 #define static_inline static
304 #define hdr_static_inline(x) x
306 #define static_inline static inline
307 #define hdr_static_inline(x) static inline x
311 hdr_static_inline(afs_int64) afs_cast_int32(afs_int32 d) { return (afs_int64) d; }
312 hdr_static_inline(afs_uint64) afs_cast_uint32(afs_uint32 d) { return (afs_uint64) d; }
314 hdr_static_inline(long long) afs_cast_int32(afs_int32 d) { return (long long) d; }
315 hdr_static_inline(unsigned long long) afs_cast_uint32(afs_uint32 d) { return (unsigned long long) d; }
318 #endif /* OPENAFS_CONFIG_AFS_STDS_H */