Pass -shared when linking some shared libraries
[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 typedef struct afs_hyper_t {    /* unsigned 64 bit integers */
132     unsigned int high;
133     unsigned int low;
134 } afs_hyper_t;
135
136 #define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
137     ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
138 #define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
139 #define hiszero(a) ((a).low == 0 && (a).high == 0)
140 #define hfitsin32(a) ((a).high == 0)
141 #define hset(a,b) ((a) = (b))
142 #define hzero(a) ((a).low = 0, (a).high = 0)
143 #define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
144 #define hget32(i,a) ((i) = (a).low)
145 #define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
146 #define hset32(a,i) ((a).high = 0, (a).low = (i))
147 #define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))
148 #define hgetlo(a) ((a).low)
149 #define hgethi(a) ((a).high)
150 #define hshlft(a,n)                                                        \
151      { /*Shift Left n bits*/                                               \
152         int s = sizeof((a).low) * 8; /*#bits*/                             \
153         if ((n) <= 0) { /*No shift*/                                       \
154         } else if ((n) >= 2*s) { /*Shift off all bits*/                    \
155            (a).high = (a).low = 0;                                         \
156         } else if ((n) < s) { /*Part of low shifted into high*/            \
157            (a).high = ((a).high<<(n)) | (((a).low>>(s-(n))) & ((1<<(n))-1)); \
158            (a).low  = (a).low << (n);                                      \
159         } else if ((n) >= s) { /*All of low shifted into high plus some*/  \
160            (a).high = (a).low << ((n)-s);                                  \
161            (a).low=0;                                                      \
162         }                                                                  \
163      }
164
165 /* The algorithm here is to check for two cases that cause a carry.  If the top
166  * two bits are different then if the sum has the top bit off then there must
167  * have been a carry.  If the top bits are both one then there is always a
168  * carry.  We assume 32 bit ints and twos complement arithmetic. */
169
170 #define SIGN 0x80000000
171 #define hadd32(a,i) \
172     ((void)((((a).low ^ (int)(i)) & SIGN) \
173       ? (((((a).low + (int)(i)) & SIGN) == 0) && (a).high++) \
174       : (((a).low & (int)(i) & SIGN) && (a).high++)), \
175      (a).low += (int)(i))
176
177 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
178
179 #if !defined(KERNEL) || defined(UKERNEL)
180 #ifndef AFS_NT40_ENV
181 #define max(a, b)               ((a) < (b) ? (b) : (a))
182 #define min(a, b)               ((a) > (b) ? (b) : (a))
183 #endif
184 /*#define abs(x)                  ((x) >= 0 ? (x) : -(x))*/
185 #endif
186
187 /* minumum length of string to pass to int_to_base64 */
188 typedef char b64_string_t[8];
189 #ifndef AFS_NT40_ENV
190 #if defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
191 char *int_to_base64();
192 int base64_to_int();
193 #else
194 char *int_to_base64(b64_string_t s, int a);
195 int base64_to_int(char *s);
196 #endif
197 #endif /* AFS_NT40_ENV */
198 /*
199  * The afsUUID data type is built in to RX
200  */
201 struct afsUUID {
202     afs_uint32 time_low;
203     afs_uint16 time_mid;
204     afs_uint16 time_hi_and_version;
205     char clock_seq_hi_and_reserved;
206     char clock_seq_low;
207     char node[6];
208 };
209 typedef struct afsUUID afsUUID;
210
211 /* for now, demand attach fileserver is only support on unix pthreads builds */
212 #if defined(DEMAND_ATTACH_ENABLE) && defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
213 #define AFS_DEMAND_ATTACH_FS 1
214 #endif
215
216 #if defined(BUILD_RXGK) && defined(AFS_PTHREAD_ENV) && !defined(KERNEL)
217 /* Only build GSS bits of code on non-kernel pthread builds */
218 # define AFS_RXGK_GSS_ENV 1
219 #endif
220
221 #if defined(ENABLE_RXGK) && !defined(UKERNEL) && (defined(AFS_PTHREAD_ENV) || defined(KERNEL))
222 /* Only enable RXGK bits for userspace pthread or non-ukernel kernel code */
223 # define AFS_RXGK_ENV 1
224 #endif
225
226 /* A macro that can be used when printf'ing 64 bit integers, as Unix and
227  * windows use a different format string
228  */
229 #ifdef AFS_NT40_ENV
230 # define AFS_INT64_FMT "I64d"
231 # define AFS_UINT64_FMT "I64u"
232 # define AFS_PTR_FMT   "p"
233 # define AFS_SIZET_FMT "Iu"
234 #else
235 # define AFS_INT64_FMT "lld"
236 # define AFS_UINT64_FMT "llu"
237 # define AFS_PTR_FMT   "p"
238 # ifdef PRINTF_TAKES_Z_LEN
239 #  define AFS_SIZET_FMT "zu"
240 # else
241 #  define AFS_SIZET_FMT "lu"
242 # endif /* PRINTF_TAKES_Z_LEN */
243 #endif /* AFS_NT40_ENV */
244 #define AFS_VOLID_FMT "lu"
245
246 /* Functions to safely cast afs_int32 and afs_uint32 so they can be used in
247  * printf statemements with %ld and %lu
248  */
249 #ifdef AFS_NT40_ENV
250 #define static_inline __inline static
251 #define hdr_static_inline(x) __inline static x
252 #elif defined(AFS_HPUX_ENV) || defined(AFS_USR_HPUX_ENV)
253 /* The HPUX compiler can segfault on 'static __inline', so fall back to
254  * just 'static' so we can at least compile */
255 #define static_inline static
256 #define hdr_static_inline(x) static x
257 #elif defined(AFS_AIX_ENV) || defined(AFS_USR_AIX_ENV)
258 #define static_inline static
259 #define hdr_static_inline(x) static x
260 #elif defined(AFS_SGI_ENV) || defined(AFS_USR_SGI_ENV)
261 #define static_inline static
262 #define hdr_static_inline(x) x
263 #elif defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV) \
264       && defined(HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE)
265 #define static_inline static __inline __attribute__((always_inline))
266 #define hdr_static_inline(x) static __inline __attribute__((always_inline)) x
267 #else
268 #define static_inline static inline
269 #define hdr_static_inline(x) static inline x
270 #endif
271
272 hdr_static_inline(long) afs_printable_int32_ld(afs_int32 d) { return (long) d; }
273
274 hdr_static_inline(unsigned long) afs_printable_uint32_lu(afs_uint32 d) { return (unsigned long) d; }
275
276 hdr_static_inline(long long) afs_printable_int64_ld(afs_int64 d) { return (long long) d; }
277
278 hdr_static_inline(unsigned long long) afs_printable_uint64_lu(afs_uint64 d) { return (unsigned long long) d; }
279
280 #ifdef AFS_64BITUSERPOINTER_ENV
281 #define afs_pointer_to_int(p)      ((afs_uint32)  (afs_uint64) (p))
282 #define afs_int_to_pointer(i)     ((void *) (afs_uint64) (i))
283 #else
284 #define afs_pointer_to_int(p)      ((afs_uint32)   (p))
285 #define afs_int_to_pointer(i)      ((void *)  (i))
286 #endif
287
288 #ifdef HAVE_FUNC_ATTRIBUTE_UNUSED
289 # define AFS_UNUSED __attribute__((unused))
290 #else
291 # define AFS_UNUSED
292 #endif
293
294 #ifdef HAVE_FUNC_ATTRIBUTE_FORMAT
295 # define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
296 #else
297 # define AFS_ATTRIBUTE_FORMAT(style,x,y)
298 #endif
299
300 #ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
301 # define AFS_NORETURN __attribute__((__noreturn__))
302 #else
303 # define AFS_NORETURN
304 #endif
305
306 #ifdef HAVE_FUNC_ATTRIBUTE_NONNULL
307 # define AFS_NONNULL(x) __attribute__((__nonnull__ x))
308 #else
309 # define AFS_NONNULL(x)
310 #endif
311
312 /*
313  * Conditionally remove unreached statements under Solaris Studio.
314  */
315 #if defined(__SUNPRO_C)
316 # define AFS_UNREACHED(x)
317 #else
318 # define AFS_UNREACHED(x)  x
319 #endif
320
321 #endif /* OPENAFS_CONFIG_AFS_STDS_H */