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 typedef short afs_int16;
48 typedef unsigned short afs_uint16;
50 typedef int afs_int32;
51 typedef unsigned int afs_uint32;
52 typedef long long afs_int64;
53 typedef unsigned long long afs_uint64;
54 #define ZeroInt64(a) (a) = 0
55 #define AssignInt64(a, b) *(a) = (b)
56 #define AddInt64(a,b,c) *(c) = (a) + (b)
57 #define SubtractInt64(a,b,c) *(c) = (afs_int64)(a) - (afs_int64)(b)
58 #define CompareInt64(a,b) (afs_int64)(a) - (afs_int64)(b)
59 #define NonZeroInt64(a) (a)
60 #define Int64ToInt32(a) (a) & 0xFFFFFFFFL
61 #define FillInt64(t,h,l) (t) = (h); (t) <<= 32; (t) |= (l);
62 #define SplitInt64(t,h,l) (h) = (t) >> 32; (l) = (t) & 0xFFFFFFFF;
63 #else /* AFS_64BIT_ENV */
64 typedef long afs_int32;
65 typedef unsigned long afs_uint32;
71 typedef struct Int64 afs_int64;
77 typedef struct u_Int64 afs_uint64;
78 #define ZeroInt64(a) (a).high = (a).low = 0
79 #define AssignInt64(a, b) (b)->high = (a).high; (b)->low = (a).low
80 #define NonZeroInt64(a) (a).low || (a).high
81 #define Int64ToInt32(a) (a).low
82 #define FillInt64(t,h,l) (t).high = (h); (t).low = (l);
83 #define SplitInt64(t,h,l) (h) = (t).high; (l) = (t).low;
84 #endif /* AFS_64BIT_ENV */
86 /* AFS_64BIT_CLIENT should presently be set only for AFS_64BIT_ENV systems */
88 #ifdef AFS_64BIT_CLIENT
89 typedef afs_int64 afs_size_t;
90 typedef afs_uint64 afs_offs_t;
91 #else /* AFS_64BIT_CLIENT */
92 typedef afs_int32 afs_size_t;
93 typedef afs_uint32 afs_offs_t;
94 #endif /* AFS_64BIT_CLIENT */
96 #ifdef AFS_LARGEFILE_ENV
97 typedef afs_int64 afs_foff_t;
98 typedef afs_uint64 afs_fsize_t;
99 typedef afs_int64 afs_sfsize_t;
100 #define SplitOffsetOrSize(t,h,l) SplitInt64(t,h,l)
101 #else /* !AFS_LARGEFILE_ENV */
102 typedef afs_int32 afs_foff_t;
103 typedef afs_uint32 afs_fsize_t;
104 typedef afs_int32 afs_sfsize_t;
105 #define SplitOffsetOrSize(t,h,l) (h) = 0; (l) = (t);
106 #endif /* !AFS_LARGEFILE_ENV */
108 /* Maximum integer sizes. Also what is expected by %lld, %llu in
110 #ifdef AFS_64BIT_CLIENT
111 typedef afs_int64 afs_intmax_t;
112 typedef afs_uint64 afs_uintmax_t;
113 #else /* !AFS_64BIT_CLIENT */
114 typedef afs_int32 afs_intmax_t;
115 typedef afs_uint32 afs_uintmax_t;
116 #endif /* !AFS_64BIT_CLIENT */
118 /* you still have to include <netinet/in.h> to make these work */
126 /* Since there is going to be considerable use of 64 bit integers we provide
127 * some assistence in this matter. The hyper type is supposed to be compatible
128 * with the afsHyper type: the same macros will work on both. */
130 #if defined(AFS_64BIT_ENV) && 0
132 typedef unsigned long afs_hyper_t;
134 #define hcmp(a,b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
135 #define hsame(a,b) ((a) == (b))
136 #define hiszero(a) ((a) == 0)
137 #define hfitsin32(a) ((a) & 0xffffffff00000000) == 0)
138 #define hset(a,b) ((a) = (b))
139 #define hzero(a) ((a) = 0)
140 #define hones(a) ((a) = ~((unsigned long)0))
141 #define hget32(i,a) ((i) = (unsigned int)(a))
142 #define hget64(hi,lo,a) ((lo) = ((unsigned int)(a)), (hi) = ((a) & (0xffffffff00000000)))
143 #define hset32(a,i) ((a) = ((unsigned int)(i)))
144 #define hset64(a,hi,lo) ((a) = (((hi) << 32) | (lo)))
145 #define hgetlo(a) ((a) & 0xffffffff)
146 #define hgethi(a) (((unsigned int)(a)) >> 32)
147 #define hadd(a,b) ((a) += (b))
149 #define hadd32(a,b) ((a) += (b))
150 #define hshlft(a,n) ((a)<<(n))
152 #else /* AFS_64BIT_ENV */
154 typedef struct afs_hyper_t { /* unsigned 64 bit integers */
159 #define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
160 ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
161 #define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
162 #define hiszero(a) ((a).low == 0 && (a).high == 0)
163 #define hfitsin32(a) ((a).high == 0)
164 #define hset(a,b) ((a) = (b))
165 #define hzero(a) ((a).low = 0, (a).high = 0)
166 #define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
167 #define hget32(i,a) ((i) = (a).low)
168 #define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
169 #define hset32(a,i) ((a).high = 0, (a).low = (i))
170 #define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))
171 #define hgetlo(a) ((a).low)
172 #define hgethi(a) ((a).high)
173 #define hshlft(a,n) \
174 { /*Shift Left n bits*/ \
175 int s = sizeof((a).low) * 8; /*#bits*/ \
176 if ((n) <= 0) { /*No shift*/ \
177 } else if ((n) >= 2*s) { /*Shift off all bits*/ \
178 (a).high = (a).low = 0; \
179 } else if ((n) < s) { /*Part of low shifted into high*/ \
180 (a).high = ((a).high<<(n)) | (((a).low>>(s-(n))) & (1<<(n))-1); \
181 (a).low = (a).low << (n); \
182 } else if ((n) >= s) { /*All of low shifted into high plus some*/ \
183 (a).high = (a).low << ((n)-s); \
188 /* The algorithm here is to check for two cases that cause a carry. If the top
189 * two bits are different then if the sum has the top bit off then there must
190 * have been a carry. If the top bits are both one then there is always a
191 * carry. We assume 32 bit ints and twos complement arithmetic. */
193 #define SIGN 0x80000000
194 #define hadd32(a,i) \
195 (((((a).low ^ (int)(i)) & SIGN) \
196 ? (((((a).low + (int)(i)) & SIGN) == 0) && (a).high++) \
197 : (((a).low & (int)(i) & SIGN) && (a).high++)), \
200 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
201 #endif /* AFS_64BIT_ENV */
205 #define max(a, b) ((a) < (b) ? (b) : (a))
206 #define min(a, b) ((a) > (b) ? (b) : (a))
208 /*#define abs(x) ((x) >= 0 ? (x) : -(x))*/
211 /* minumum length of string to pass to int_to_base64 */
212 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);
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 #endif /* OPENAFS_CONFIG_AFS_STDS_H */