Configure glue for rxgk
[openafs.git] / src / config / stds.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 /*
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.
14  */
15
16 #ifndef OPENAFS_AFS_CONFIG_STDS_H
17 #define OPENAFS_AFS_CONFIG_STDS_H       1
18
19 #include <afs/param.h>
20 #include <sys/types.h>
21
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) */
25
26 #ifndef MACRO_BEGIN
27 #define MACRO_BEGIN     do {
28 #endif
29 #ifndef MACRO_END
30 #define MACRO_END       } while (0)
31 #endif
32
33 typedef void *opaque;
34
35 #ifndef _ATT4
36 #if defined(__HIGHC__)
37 /*
38  * keep HC from complaining about the use of "old-style" function definitions
39  * with prototypes
40  */
41 pragma Off(Prototype_override_warnings);
42 #endif /* defined(__HIGHC__) */
43 #endif
44
45 /* Now some types to enhance portability.  Always use these on the wire or when
46  * laying out shared structures on disk. */
47
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
51 #endif */
52
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
59
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;
67 #else
68 typedef long long afs_int64;
69 typedef unsigned long long afs_uint64;
70 #endif
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 #ifndef HAVE_INT64TOINT32
89 #define Int64ToInt32(a)    ((a) & MAX_AFS_UINT32)
90 #endif
91 #define FillInt64(t,h,l) (t) = ((afs_int64)(h) << 32) | (l)
92 #define SplitInt64(t,h,l) (h) = ((afs_int64)(t)) >> 32; (l) = (t) & MAX_AFS_UINT32
93 #define RoundInt64ToInt32(a)    (((a) > MAX_AFS_UINT32) ? MAX_AFS_UINT32 : (a))
94 #define RoundInt64ToInt31(a)    (((a) > MAX_AFS_INT32) ? MAX_AFS_INT32 : (a))
95
96 #ifdef AFS_64BIT_CLIENT
97 typedef afs_int64 afs_size_t;
98 typedef afs_uint64 afs_offs_t;
99 #else /* AFS_64BIT_CLIENT */
100 typedef afs_int32 afs_size_t;
101 typedef afs_uint32 afs_offs_t;
102 #endif /* AFS_64BIT_CLIENT */
103
104 typedef afs_int64 afs_foff_t;
105 typedef afs_uint64 afs_fsize_t;
106 typedef afs_int64 afs_sfsize_t;
107 #define SplitOffsetOrSize(t,h,l) SplitInt64(t,h,l)
108
109 /* Maximum integer sizes.  Also what is expected by %lld, %llu in
110  * afs_snprintf. */
111 #ifdef AFS_64BIT_CLIENT
112 typedef afs_int64 afs_intmax_t;
113 typedef afs_uint64 afs_uintmax_t;
114 #else /* !AFS_64BIT_CLIENT */
115 typedef afs_int32 afs_intmax_t;
116 typedef afs_uint32 afs_uintmax_t;
117 #endif /* !AFS_64BIT_CLIENT */
118
119 /* you still have to include <netinet/in.h> to make these work */
120
121 #define hton32 htonl
122 #define hton16 htons
123 #define ntoh32 ntohl
124 #define ntoh16 ntohs
125
126
127 /* Since there is going to be considerable use of 64 bit integers we provide
128  * some assistence in this matter.  The hyper type is supposed to be compatible
129  * with the afsHyper type: the same macros will work on both. */
130
131 #if 0
132
133 typedef unsigned long afs_hyper_t;
134
135 #define hcmp(a,b)       ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
136 #define hsame(a,b)      ((a) == (b))
137 #define hiszero(a)      ((a) == 0)
138 #define hfitsin32(a)    ((a) & 0xffffffff00000000) == 0)
139 #define hset(a,b)       ((a) = (b))
140 #define hzero(a)        ((a) = 0)
141 #define hones(a)        ((a) = ~((unsigned long)0))
142 #define hget32(i,a)     ((i) = (unsigned int)(a))
143 #define hget64(hi,lo,a) ((lo) = ((unsigned int)(a)), (hi) = ((a) & (0xffffffff00000000)))
144 #define hset32(a,i)     ((a) = ((unsigned int)(i)))
145 #define hset64(a,hi,lo) ((a) = (((hi) << 32) | (lo)))
146 #define hgetlo(a)       ((a) & 0xffffffff)
147 #define hgethi(a)       (((unsigned int)(a)) >> 32)
148 #define hadd(a,b)       ((a) += (b))
149 /* XXX */
150 #define hadd32(a,b)     ((a) += (b))
151 #define hshlft(a,n)     ((a)<<(n))
152
153 #else /* 0*/
154
155 typedef struct afs_hyper_t {    /* unsigned 64 bit integers */
156     unsigned int high;
157     unsigned int low;
158 } afs_hyper_t;
159
160 #define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
161     ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
162 #define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
163 #define hiszero(a) ((a).low == 0 && (a).high == 0)
164 #define hfitsin32(a) ((a).high == 0)
165 #define hset(a,b) ((a) = (b))
166 #define hzero(a) ((a).low = 0, (a).high = 0)
167 #define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
168 #define hget32(i,a) ((i) = (a).low)
169 #define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
170 #define hset32(a,i) ((a).high = 0, (a).low = (i))
171 #define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))
172 #define hgetlo(a) ((a).low)
173 #define hgethi(a) ((a).high)
174 #define hshlft(a,n)                                                        \
175      { /*Shift Left n bits*/                                               \
176         int s = sizeof((a).low) * 8; /*#bits*/                             \
177         if ((n) <= 0) { /*No shift*/                                       \
178         } else if ((n) >= 2*s) { /*Shift off all bits*/                    \
179            (a).high = (a).low = 0;                                         \
180         } else if ((n) < s) { /*Part of low shifted into high*/            \
181            (a).high = ((a).high<<(n)) | (((a).low>>(s-(n))) & ((1<<(n))-1)); \
182            (a).low  = (a).low << (n);                                      \
183         } else if ((n) >= s) { /*All of low shifted into high plus some*/  \
184            (a).high = (a).low << ((n)-s);                                  \
185            (a).low=0;                                                      \
186         }                                                                  \
187      }
188
189 /* The algorithm here is to check for two cases that cause a carry.  If the top
190  * two bits are different then if the sum has the top bit off then there must
191  * have been a carry.  If the top bits are both one then there is always a
192  * carry.  We assume 32 bit ints and twos complement arithmetic. */
193
194 #define SIGN 0x80000000
195 #define hadd32(a,i) \
196     ((void)((((a).low ^ (int)(i)) & SIGN) \
197       ? (((((a).low + (int)(i)) & SIGN) == 0) && (a).high++) \
198       : (((a).low & (int)(i) & SIGN) && (a).high++)), \
199      (a).low += (int)(i))
200
201 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
202 #endif /* 0 */
203
204 #if !defined(KERNEL) || defined(UKERNEL)
205 #ifndef AFS_NT40_ENV
206 #define max(a, b)               ((a) < (b) ? (b) : (a))
207 #define min(a, b)               ((a) > (b) ? (b) : (a))
208 #endif
209 /*#define abs(x)                  ((x) >= 0 ? (x) : -(x))*/
210 #endif
211
212 /* minumum length of string to pass to int_to_base64 */
213 typedef char b64_string_t[8];
214 #ifndef AFS_NT40_ENV
215 #if defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
216 char *int_to_base64();
217 int base64_to_int();
218 #else
219 char *int_to_base64(b64_string_t s, int a);
220 int base64_to_int(char *s);
221 #endif
222 #endif /* AFS_NT40_ENV */
223 /*
224  * The afsUUID data type is built in to RX
225  */
226 struct afsUUID {
227     afs_uint32 time_low;
228     afs_uint16 time_mid;
229     afs_uint16 time_hi_and_version;
230     char clock_seq_hi_and_reserved;
231     char clock_seq_low;
232     char node[6];
233 };
234 typedef struct afsUUID afsUUID;
235
236 /* for now, demand attach fileserver is only support on unix pthreads builds */
237 #if defined(DEMAND_ATTACH_ENABLE) && defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
238 #define AFS_DEMAND_ATTACH_FS 1
239 #endif
240
241 #if defined(BUILD_RXGK) && defined(AFS_PTHREAD_ENV) && !defined(KERNEL)
242 /* Only build GSS bits of code on non-kernel pthread builds */
243 # define AFS_RXGK_GSS_ENV 1
244 #endif
245
246 #if defined(ENABLE_RXGK) && !defined(UKERNEL) && (defined(AFS_PTHREAD_ENV) || defined(KERNEL))
247 /* Only enable RXGK bits for userspace pthread or non-ukernel kernel code */
248 # define AFS_RXGK_ENV 1
249 #endif
250
251 /* A macro that can be used when printf'ing 64 bit integers, as Unix and
252  * windows use a different format string
253  */
254 #ifdef AFS_NT40_ENV
255 # define AFS_INT64_FMT "I64d"
256 # define AFS_UINT64_FMT "I64u"
257 # define AFS_PTR_FMT   "p"
258 # define AFS_SIZET_FMT "Iu"
259 #else
260 # define AFS_INT64_FMT "lld"
261 # define AFS_UINT64_FMT "llu"
262 # define AFS_PTR_FMT   "p"
263 # ifdef PRINTF_TAKES_Z_LEN
264 #  define AFS_SIZET_FMT "zu"
265 # else
266 #  define AFS_SIZET_FMT "lu"
267 # endif /* PRINTF_TAKES_Z_LEN */
268 #endif /* AFS_NT40_ENV */
269 #define AFS_VOLID_FMT "lu"
270
271 /* Functions to safely cast afs_int32 and afs_uint32 so they can be used in
272  * printf statemements with %ld and %lu
273  */
274 #ifdef AFS_NT40_ENV
275 #define static_inline __inline static
276 #define hdr_static_inline(x) __inline static x
277 #elif defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV)
278 /* The HPUX compiler can segfault on 'static __inline', so fall back to
279  * just 'static' so we can at least compile */
280 #define static_inline static
281 #define hdr_static_inline(x) static x
282 #elif defined(AFS_AIX_ENV) || defined(AFS_USR_AIX_ENV)
283 #define static_inline static
284 #define hdr_static_inline(x) static x
285 #elif defined(AFS_SGI_ENV) || defined(AFS_USR_SGI_ENV)
286 #define static_inline static
287 #define hdr_static_inline(x) x
288 #elif defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV) \
289       && defined(HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE)
290 #define static_inline static __inline __attribute__((always_inline))
291 #define hdr_static_inline(x) static __inline __attribute__((always_inline)) x
292 #else
293 #define static_inline static inline
294 #define hdr_static_inline(x) static inline x
295 #endif
296
297 hdr_static_inline(long) afs_printable_int32_ld(afs_int32 d) { return (long) d; }
298
299 hdr_static_inline(unsigned long) afs_printable_uint32_lu(afs_uint32 d) { return (unsigned long) d; }
300
301 hdr_static_inline(long long) afs_printable_int64_ld(afs_int64 d) { return (long long) d; }
302
303 hdr_static_inline(unsigned long long) afs_printable_uint64_lu(afs_uint64 d) { return (unsigned long long) d; }
304
305 #ifdef AFS_64BITUSERPOINTER_ENV
306 #define afs_pointer_to_int(p)      ((afs_uint32)  (afs_uint64) (p))
307 #define afs_int_to_pointer(i)     ((void *) (afs_uint64) (i))
308 #else
309 #define afs_pointer_to_int(p)      ((afs_uint32)   (p))
310 #define afs_int_to_pointer(i)      ((void *)  (i))
311 #endif
312
313 #ifdef HAVE_FUNC_ATTRIBUTE_UNUSED
314 # define AFS_UNUSED __attribute__((unused))
315 #else
316 # define AFS_UNUSED
317 #endif
318
319 #ifdef HAVE_FUNC_ATTRIBUTE_FORMAT
320 # define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
321 #else
322 # define AFS_ATTRIBUTE_FORMAT(style,x,y)
323 #endif
324
325 #ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
326 # define AFS_NORETURN __attribute__((__noreturn__))
327 #else
328 # define AFS_NORETURN
329 #endif
330
331 #ifdef HAVE_FUNC_ATTRIBUTE_NONNULL
332 # define AFS_NONNULL(x) __attribute__((__nonnull__ x))
333 #else
334 # define AFS_NONNULL(x)
335 #endif
336
337 /*
338  * Conditionally remove unreached statements under Solaris Studio.
339  */
340 #if defined(__SUNPRO_C)
341 # define AFS_UNREACHED(x)
342 #else
343 # define AFS_UNREACHED(x)  x
344 #endif
345
346 #endif /* OPENAFS_CONFIG_AFS_STDS_H */