Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / config / stds.h
1 /* Copyright (C) 1998, 1990 Transarc Corporation - All rights reserved */
2
3
4 #ifndef TRANSARC_AFS_CONFIG_STDS_H
5 #define TRANSARC_AFS_CONFIG_STDS_H      1
6
7 #include <afs/param.h>
8 #include <sys/types.h>
9
10 #define IN              /* indicates a parameter is read in */
11 #define OUT             /* indicates a parameter is sent out (a ptr) */
12 #define INOUT           /* indicates a parameter is read in and sent out (a ptr) */
13
14 #ifndef MACRO_BEGIN
15 #define MACRO_BEGIN     do {
16 #endif
17 #ifndef MACRO_END
18 #define MACRO_END       } while (0)
19 #endif
20
21 typedef void *opaque;
22
23 #ifndef _ATT4
24 #if defined(__HIGHC__)
25 /*
26  * keep HC from complaining about the use of "old-style" function definitions
27  * with prototypes
28  */
29 pragma Off(Prototype_override_warnings);
30 #endif /* defined(__HIGHC__) */
31 #endif
32 /*
33  * This makes including the RCS id in object files less painful.  Put this near
34  * the beginning of .c files (not .h files).  Do NOT follow it with a
35  * semi-colon.  The argument should be a double quoted string containing the
36  * standard RCS Header keyword.
37  */
38
39 /* Now some types to enhance portability.  Always use these on the wire or when
40  * laying out shared structures on disk. */
41
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
45 #endif */
46
47 typedef short            afs_int16;
48 typedef unsigned short   afs_uint16;
49 #ifdef  AFS_64BIT_ENV
50 typedef int              afs_int32;
51 typedef unsigned int     afs_uint32;
52 #else   /* AFS_64BIT_ENV */
53 typedef long             afs_int32;
54 typedef unsigned long    afs_uint32;
55 #endif  /* AFS_64BIT_ENV */
56
57 /* you still have to include <netinet/in.h> to make these work */
58
59 #define hton32 htonl
60 #define hton16 htons
61 #define ntoh32 ntohl
62 #define ntoh16 ntohs
63
64
65 /* Since there is going to be considerable use of 64 bit integers we provide
66  * some assistence in this matter.  The hyper type is supposed to be compatible
67  * with the afsHyper type: the same macros will work on both. */
68
69 #if     defined(AFS_64BIT_ENV) && 0
70
71 typedef unsigned long   afs_hyper_t;
72
73 #define hcmp(a,b)       ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
74 #define hsame(a,b)      ((a) == (b))
75 #define hiszero(a)      ((a) == 0)
76 #define hfitsin32(a)    ((a) & 0xffffffff00000000) == 0)
77 #define hset(a,b)       ((a) = (b))
78 #define hzero(a)        ((a) = 0)
79 #define hones(a)        ((a) = ~((unsigned long)0))
80 #define hget32(i,a)     ((i) = (unsigned int)(a))
81 #define hget64(hi,lo,a) ((lo) = ((unsigned int)(a)), (hi) = ((a) & (0xffffffff00000000)))
82 #define hset32(a,i)     ((a) = ((unsigned int)(i)))
83 #define hset64(a,hi,lo) ((a) = (((hi) << 32) | (lo)))
84 #define hgetlo(a)       ((a) & 0xffffffff)
85 #define hgethi(a)       (((unsigned int)(a)) >> 32)
86 #define hadd(a,b)       ((a) += (b))
87 /* XXX */
88 #define hadd32(a,b)     ((a) += (b))
89 #define hshlft(a,n)     ((a)<<(n))
90
91 #else   /* AFS_64BIT_ENV */
92
93 typedef struct afs_hyper_t { /* unsigned 64 bit integers */
94     unsigned int high;
95     unsigned int low;
96 } afs_hyper_t;
97
98 #define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
99     ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
100 #define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
101 #define hiszero(a) ((a).low == 0 && (a).high == 0)
102 #define hfitsin32(a) ((a).high == 0)
103 #define hset(a,b) ((a) = (b))
104 #define hzero(a) ((a).low = 0, (a).high = 0)
105 #define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
106 #define hget32(i,a) ((i) = (a).low)
107 #define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
108 #define hset32(a,i) ((a).high = 0, (a).low = (i))
109 #define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))
110 #define hgetlo(a) ((a).low)
111 #define hgethi(a) ((a).high)
112 #define hshlft(a,n)                                                        \
113      { /*Shift Left n bits*/                                               \
114         int s = sizeof((a).low) * 8; /*#bits*/                             \
115         if ((n) <= 0) { /*No shift*/                                       \
116         } else if ((n) >= 2*s) { /*Shift off all bits*/                    \
117            (a).high = (a).low = 0;                                         \
118         } else if ((n) < s) { /*Part of low shifted into high*/            \
119            (a).high = ((a).high<<(n)) | (((a).low>>(s-(n))) & (1<<(n))-1); \
120            (a).low  = (a).low << (n);                                      \
121         } else if ((n) >= s) { /*All of low shifted into high plus some*/  \
122            (a).high = (a).low << ((n)-s);                                  \
123            (a).low=0;                                                      \
124         }                                                                  \
125      }
126
127 /* The algorithm here is to check for two cases that cause a carry.  If the top
128  * two bits are different then if the sum has the top bit off then there must
129  * have been a carry.  If the top bits are both one then there is always a
130  * carry.  We assume 32 bit ints and twos complement arithmetic. */
131
132 #define SIGN 0x80000000
133 #define hadd32(a,i) \
134     (((((a).low ^ (int)(i)) & SIGN) \
135       ? (((((a).low + (int)(i)) & SIGN) == 0) && (a).high++) \
136       : (((a).low & (int)(i) & SIGN) && (a).high++)), \
137      (a).low += (int)(i))
138
139 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
140 #endif  /* AFS_64BIT_ENV */
141
142 #ifndef KERNEL
143 #ifndef AFS_NT40_ENV
144 #define max(a, b)               ((a) < (b) ? (b) : (a))
145 #define min(a, b)               ((a) > (b) ? (b) : (a))
146 #endif
147 /*#define abs(x)                  ((x) >= 0 ? (x) : -(x))*/
148 #endif
149
150 #if defined(AFS_LINUX20_ENV) && defined(KERNEL)
151 /* This is here instead of osi_machdep.h so fcrypt.c can pick it up. */
152 #include "../h/string.h"
153 #define bcopy(F,T,C) memcpy((T), (F), (C))
154 #endif
155
156
157 /* minumum length of string to pass to int_to_base64 */
158 typedef char b64_string_t[8];
159 #if defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
160 char *int_to_base64();
161 int base64_to_int();
162 #else
163 char *int_to_base64(b64_string_t s, int a);
164 int base64_to_int(char *s);
165 #endif
166
167 /*
168  * The afsUUID data type is built in to RX
169  */
170 struct afsUUID {
171     afs_uint32 time_low;
172     afs_uint16 time_mid;
173     afs_uint16 time_hi_and_version;
174     char clock_seq_hi_and_reserved;
175     char clock_seq_low;
176     char node[6];
177 };
178 typedef struct afsUUID afsUUID;
179 extern int xdr_afsUUID();
180
181 #endif /* TRANSARC_CONFIG_AFS_STDS_H */