]> arthur.barton.de Git - netatalk.git/blob - sys/netatalk/endian.h
Fix compilation with Solaris 10 on x86, from HEAD
[netatalk.git] / sys / netatalk / endian.h
1 /*
2  * $Id: endian.h,v 1.7.12.2 2009-01-10 20:14:29 didg Exp $
3  *
4  * Copyright (c) 1990,1991 Regents of The University of Michigan.
5  * All Rights Reserved. See COPYRIGHT.
6  *
7  * This file handles both byte ordering and integer sizes.
8  */
9
10 #ifndef _ATALK_ENDIAN_H_
11 #define _ATALK_ENDIAN_H_
12
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif /* HAVE_CONFIG_H */
16
17 #include <sys/types.h>
18 #include <netinet/in.h>
19
20 #ifdef _IBMR2
21 #include <sys/machine.h>
22 #endif /*_IBMR2*/
23
24 #ifdef _ISOC9X_SOURCE
25 #include <inttypes.h>
26 #ifndef __BIT_TYPES_DEFINED__
27 #define __BIT_TYPES_DEFINED__
28 typedef uint8_t        u_int8_t;
29 typedef uint16_t       u_int16_t;
30 typedef uint32_t       u_int32_t;
31 typedef uint64_t       u_int64_t;
32 #endif /* ! __BIT_TYPES_DEFINED__ */
33 #else
34
35 /* handle sunos and solaris */
36 #ifdef sun
37 #ifdef BSD4_3
38 #include <sys/bitypes.h>
39 #else /* BSD4_3 */
40 /* solaris and sunos don't consistently define u_int*_t. */
41 typedef unsigned char      u_int8_t;
42 typedef unsigned short     u_int16_t;
43 typedef unsigned int       u_int32_t;
44 typedef int                int32_t;
45 #endif /* BSD4_3 */
46
47 typedef unsigned long long u_int64_t;
48
49 #ifndef _SSIZE_T
50 #define _SSIZE_T
51 typedef int ssize_t;
52 #endif /* ssize_t */
53
54 #else /* sun */
55
56 /* luckily ultrix is dead. as a result, we know what the sizes of
57  * various types are forever. this makes some assumptions about integer
58  * sizes. */
59 #if defined (ultrix) || defined(HAVE_32BIT_LONGS) || defined(HAVE_64BIT_LONGS)
60 #ifndef __BIT_TYPES_DEFINED__
61 #define __BIT_TYPES_DEFINED__
62 typedef unsigned char  u_int8_t;
63 typedef unsigned short u_int16_t;
64 typedef unsigned int   u_int32_t;
65 typedef int            int32_t;
66 #endif
67 #endif /* ultrix || HAVE_32BIT_LONGS || HAVE_64BIT_LONGS */
68
69 #ifdef ultrix
70 typedef int            ssize_t;
71 #endif /* ultrix */
72
73 #ifdef HAVE_64BIT_LONGS
74 typedef unsigned long u_int64_t;
75 #else /* HAVE_64BIT_LONGS */
76 /* check for long long support. currently, i assume that if 64-bit
77  * ints exist that their made available via long long */
78 #ifdef linux
79 #include <endian.h> /* i think this is here for libc4 */
80 #else /* linux */
81 #if defined(HAVE_32BIT_LONGS) && !(defined(BSD4_4) || \
82                                   defined(NO_LARGE_VOL_SUPPORT))
83 typedef unsigned long long  u_int64_t;
84 #endif /* HAVE_32BIT_LONGS || !BSD4_4 || NO_LARGE_VOL_SUPPORT */
85 #endif /* linux */
86 #endif /* HAVE_64BIT_LONGS */
87 #endif /* sun */
88 #endif /* ISOC9X */
89
90 # ifndef BYTE_ORDER
91 #define LITTLE_ENDIAN   1234
92 #define BIG_ENDIAN      4321
93 #define PDP_ENDIAN      3412
94
95
96 #if defined(WORDS_BIGENDIAN) || defined(_BIG_ENDIAN)
97 #define BYTE_ORDER      BIG_ENDIAN
98 #else
99 #define BYTE_ORDER      LITTLE_ENDIAN
100 #endif /* WORDS_BIGENDIAN */
101
102 # ifndef ntohl
103 # if defined( sun ) || defined( ultrix ) || defined( _IBMR2 )
104 #if BYTE_ORDER == BIG_ENDIAN
105 #define ntohl(x)        (x)
106 #define ntohs(x)        (x)
107 #define htonl(x)        (x)
108 #define htons(x)        (x)
109
110 #else /* BYTE_ORDER == BIG_ENDIAN */
111 #if defined( mips ) && defined( KERNEL )
112 #define ntohl(x)        nuxi_l(x)
113 #define ntohs(x)        nuxi_s(x)
114 #define htonl(x)        nuxi_l(x)
115 #define htons(x)        nuxi_s(x)
116
117 #else /* mips && KERNEL */
118
119 #if !( defined( sun ) && ( defined( i386 ) || defined(__x86_64) ) )
120 unsigned short ntohs(), htons();
121 unsigned int  ntohl(), htonl();
122 #endif /* ! ( sun && i386 ) */
123
124 #endif /* mips && KERNEL */
125 #endif /* BYTE_ORDER == BIGENDIAN*/
126 # endif /* sun ultrix _IBMR2 */
127 # endif /* ntohl */
128 #endif /* BYTE_ORDER */
129
130 #endif /* _ATALK_ENDIAN_H_ */
131