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