1 /* Copyright 2003 Massachusetts Institute of Technology. All rights reserved. */
2 /* Platform-dependent junk. */
8 # if __STDC_VERSION__ >= 199901L
9 /* C99 supports inline, don't do anything. */
10 # elif defined(__GNUC__)
11 # define inline __inline__ /* this form silences -pedantic warnings */
12 # elif defined(__mips) && defined(__sgi)
13 # define inline __inline /* IRIX used at MIT does inline but not c99 yet */
14 # elif defined(__sun) && __SUNPRO_C >= 0x540
15 /* The Forte Developer 7 C compiler supports "inline". */
16 # elif defined(_WIN32)
17 # define inline __inline
19 # define inline /* nothing, just static */
25 /* 64-bit support: krb5_ui_8 and krb5_int64.
27 This should move to krb5.h eventually, but without the namespace
28 pollution from the autoconf macros. */
29 #if defined(HAVE_STDINT_H) || defined(HAVE_INTTYPES_H)
33 # ifdef HAVE_INTTYPES_H
34 # include <inttypes.h>
36 # define INT64_TYPE int64_t
37 # define UINT64_TYPE uint64_t
39 # define INT64_TYPE signed __int64
40 # define UINT64_TYPE unsigned __int64
41 #else /* not Windows, and neither stdint.h nor inttypes.h */
42 # define INT64_TYPE signed long long
43 # define UINT64_TYPE unsigned long long
46 /* Read and write integer values as (unaligned) octet strings in
49 Add per-platform optimizations later if needed. (E.g., maybe x86
50 unaligned word stores and gcc/asm instructions for byte swaps,
54 store_16_be (unsigned int val, unsigned char *p)
56 p[0] = (val >> 8) & 0xff;
60 store_16_le (unsigned int val, unsigned char *p)
62 p[1] = (val >> 8) & 0xff;
66 store_32_be (unsigned int val, unsigned char *p)
68 p[0] = (val >> 24) & 0xff;
69 p[1] = (val >> 16) & 0xff;
70 p[2] = (val >> 8) & 0xff;
74 store_32_le (unsigned int val, unsigned char *p)
76 p[3] = (val >> 24) & 0xff;
77 p[2] = (val >> 16) & 0xff;
78 p[1] = (val >> 8) & 0xff;
82 store_64_be (UINT64_TYPE val, unsigned char *p)
84 p[0] = (unsigned char)((val >> 56) & 0xff);
85 p[1] = (unsigned char)((val >> 48) & 0xff);
86 p[2] = (unsigned char)((val >> 40) & 0xff);
87 p[3] = (unsigned char)((val >> 32) & 0xff);
88 p[4] = (unsigned char)((val >> 24) & 0xff);
89 p[5] = (unsigned char)((val >> 16) & 0xff);
90 p[6] = (unsigned char)((val >> 8) & 0xff);
91 p[7] = (unsigned char)((val ) & 0xff);
94 store_64_le (UINT64_TYPE val, unsigned char *p)
96 p[7] = (unsigned char)((val >> 56) & 0xff);
97 p[6] = (unsigned char)((val >> 48) & 0xff);
98 p[5] = (unsigned char)((val >> 40) & 0xff);
99 p[4] = (unsigned char)((val >> 32) & 0xff);
100 p[3] = (unsigned char)((val >> 24) & 0xff);
101 p[2] = (unsigned char)((val >> 16) & 0xff);
102 p[1] = (unsigned char)((val >> 8) & 0xff);
103 p[0] = (unsigned char)((val ) & 0xff);
105 static inline unsigned short
106 load_16_be (unsigned char *p)
108 return (p[1] | (p[0] << 8));
110 static inline unsigned short
111 load_16_le (unsigned char *p)
113 return (p[0] | (p[1] << 8));
115 static inline unsigned int
116 load_32_be (unsigned char *p)
118 return (p[3] | (p[2] << 8) | (p[1] << 16) | (p[0] << 24));
120 static inline unsigned int
121 load_32_le (unsigned char *p)
123 return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24));
125 static inline UINT64_TYPE
126 load_64_be (unsigned char *p)
128 return ((UINT64_TYPE)load_32_be(p) << 32) | load_32_be(p+4);
130 static inline UINT64_TYPE
131 load_64_le (unsigned char *p)
133 return ((UINT64_TYPE)load_32_le(p+4) << 32) | load_32_le(p);
136 #endif /* K5_PLATFORM_H */