mrafs-client-extensions-including-afs-int64-20010210
[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 #ifndef TRANSARC_AFS_CONFIG_STDS_H
11 #define TRANSARC_AFS_CONFIG_STDS_H      1
12
13 #include <afs/param.h>
14 #include <sys/types.h>
15
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) */
19
20 #ifndef MACRO_BEGIN
21 #define MACRO_BEGIN     do {
22 #endif
23 #ifndef MACRO_END
24 #define MACRO_END       } while (0)
25 #endif
26
27 typedef void *opaque;
28
29 #ifndef _ATT4
30 #if defined(__HIGHC__)
31 /*
32  * keep HC from complaining about the use of "old-style" function definitions
33  * with prototypes
34  */
35 pragma Off(Prototype_override_warnings);
36 #endif /* defined(__HIGHC__) */
37 #endif
38 /*
39  * This makes including the RCS id in object files less painful.  Put this near
40  * the beginning of .c files (not .h files).  Do NOT follow it with a
41  * semi-colon.  The argument should be a double quoted string containing the
42  * standard RCS Header keyword.
43  */
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 typedef short            afs_int16;
54 typedef unsigned short   afs_uint16;
55 #ifdef  AFS_64BIT_ENV
56 typedef int              afs_int32;
57 typedef unsigned int     afs_uint32;
58 typedef long long        afs_int64;
59 typedef  unsigned long long afs_uint64;
60  #define ZeroInt64(a)       (a) = 0
61  #define AssignInt64(a, b)   *(a) = (b)
62  #define AddInt64(a,b,c) *(c) = (a) + (b)
63  #define SubtractInt64(a,b,c) *(c) = (a) - (b)
64  #define CompareInt64(a,b) (a) - (b)
65  #define NonZeroInt64(a)                (a)
66  #define Int64ToInt32(a)    (a) & 0xFFFFFFFFL
67  #define FillInt64(t,h,l) (t) = (h); (t) <<= 32; (t) |= (l);
68  #define SplitInt64(t,h,l) (h) = (t) >> 32; (l) = (t) & 0xFFFFFFFF;
69 #else   /* AFS_64BIT_ENV */
70 typedef long             afs_int32;
71 typedef unsigned long    afs_uint32;
72
73  struct Int64 {
74     afs_int32 high;
75     afs_uint32 low;
76  };
77  typedef struct Int64 afs_int64;
78
79  struct u_Int64 {
80     afs_uint32 high;
81     afs_uint32 low;
82  };
83  typedef struct u_Int64 afs_uint64;
84  #define ZeroInt64(a) (a).high = (a).low = 0
85  #define AssignInt64(a, b) (b)->high = (a).high; (b)->low = (a).low
86  #define NonZeroInt64(a)   (a).low || (a).high
87  #define Int64ToInt32(a)    (a).low
88  #define FillInt64(t,h,l) (t).high = (h); (t).low = (l);
89  #define SplitInt64(t,h,l) (h) = (t).high; (l) = (t).low;
90 #endif  /* AFS_64BIT_ENV */
91
92 /* AFS_64BIT_CLIENT should presently be set only for AFS_64BIT_ENV systems */
93
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 */
101
102 /* you still have to include <netinet/in.h> to make these work */
103
104 #define hton32 htonl
105 #define hton16 htons
106 #define ntoh32 ntohl
107 #define ntoh16 ntohs
108
109
110 /* Since there is going to be considerable use of 64 bit integers we provide
111  * some assistence in this matter.  The hyper type is supposed to be compatible
112  * with the afsHyper type: the same macros will work on both. */
113
114 #if     defined(AFS_64BIT_ENV) && 0
115
116 typedef unsigned long   afs_hyper_t;
117
118 #define hcmp(a,b)       ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
119 #define hsame(a,b)      ((a) == (b))
120 #define hiszero(a)      ((a) == 0)
121 #define hfitsin32(a)    ((a) & 0xffffffff00000000) == 0)
122 #define hset(a,b)       ((a) = (b))
123 #define hzero(a)        ((a) = 0)
124 #define hones(a)        ((a) = ~((unsigned long)0))
125 #define hget32(i,a)     ((i) = (unsigned int)(a))
126 #define hget64(hi,lo,a) ((lo) = ((unsigned int)(a)), (hi) = ((a) & (0xffffffff00000000)))
127 #define hset32(a,i)     ((a) = ((unsigned int)(i)))
128 #define hset64(a,hi,lo) ((a) = (((hi) << 32) | (lo)))
129 #define hgetlo(a)       ((a) & 0xffffffff)
130 #define hgethi(a)       (((unsigned int)(a)) >> 32)
131 #define hadd(a,b)       ((a) += (b))
132 /* XXX */
133 #define hadd32(a,b)     ((a) += (b))
134 #define hshlft(a,n)     ((a)<<(n))
135
136 #else   /* AFS_64BIT_ENV */
137
138 typedef struct afs_hyper_t { /* unsigned 64 bit integers */
139     unsigned int high;
140     unsigned int low;
141 } afs_hyper_t;
142
143 #define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
144     ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
145 #define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
146 #define hiszero(a) ((a).low == 0 && (a).high == 0)
147 #define hfitsin32(a) ((a).high == 0)
148 #define hset(a,b) ((a) = (b))
149 #define hzero(a) ((a).low = 0, (a).high = 0)
150 #define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
151 #define hget32(i,a) ((i) = (a).low)
152 #define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
153 #define hset32(a,i) ((a).high = 0, (a).low = (i))
154 #define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))
155 #define hgetlo(a) ((a).low)
156 #define hgethi(a) ((a).high)
157 #define hshlft(a,n)                                                        \
158      { /*Shift Left n bits*/                                               \
159         int s = sizeof((a).low) * 8; /*#bits*/                             \
160         if ((n) <= 0) { /*No shift*/                                       \
161         } else if ((n) >= 2*s) { /*Shift off all bits*/                    \
162            (a).high = (a).low = 0;                                         \
163         } else if ((n) < s) { /*Part of low shifted into high*/            \
164            (a).high = ((a).high<<(n)) | (((a).low>>(s-(n))) & (1<<(n))-1); \
165            (a).low  = (a).low << (n);                                      \
166         } else if ((n) >= s) { /*All of low shifted into high plus some*/  \
167            (a).high = (a).low << ((n)-s);                                  \
168            (a).low=0;                                                      \
169         }                                                                  \
170      }
171
172 /* The algorithm here is to check for two cases that cause a carry.  If the top
173  * two bits are different then if the sum has the top bit off then there must
174  * have been a carry.  If the top bits are both one then there is always a
175  * carry.  We assume 32 bit ints and twos complement arithmetic. */
176
177 #define SIGN 0x80000000
178 #define hadd32(a,i) \
179     (((((a).low ^ (int)(i)) & SIGN) \
180       ? (((((a).low + (int)(i)) & SIGN) == 0) && (a).high++) \
181       : (((a).low & (int)(i) & SIGN) && (a).high++)), \
182      (a).low += (int)(i))
183
184 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
185 #endif  /* AFS_64BIT_ENV */
186
187 #ifndef KERNEL
188 #ifndef AFS_NT40_ENV
189 #define max(a, b)               ((a) < (b) ? (b) : (a))
190 #define min(a, b)               ((a) > (b) ? (b) : (a))
191 #endif
192 /*#define abs(x)                  ((x) >= 0 ? (x) : -(x))*/
193 #endif
194
195 #if defined(AFS_LINUX20_ENV) && defined(KERNEL)
196 /* This is here instead of osi_machdep.h so fcrypt.c can pick it up. */
197 #include "../h/string.h"
198 #define bcopy(F,T,C) memcpy((T), (F), (C))
199 #endif
200
201
202 /* minumum length of string to pass to int_to_base64 */
203 typedef char b64_string_t[8];
204 #if defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
205 char *int_to_base64();
206 int base64_to_int();
207 #else
208 char *int_to_base64(b64_string_t s, int a);
209 int base64_to_int(char *s);
210 #endif
211
212 /*
213  * The afsUUID data type is built in to RX
214  */
215 struct afsUUID {
216     afs_uint32 time_low;
217     afs_uint16 time_mid;
218     afs_uint16 time_hi_and_version;
219     char clock_seq_hi_and_reserved;
220     char clock_seq_low;
221     char node[6];
222 };
223 typedef struct afsUUID afsUUID;
224 extern int xdr_afsUUID();
225
226 #endif /* TRANSARC_CONFIG_AFS_STDS_H */