]> arthur.barton.de Git - netatalk.git/blob - sys/netatalk/endian.h
Changes made by Michel Jouvin - jouvin@lal.in2p3.fr - 23/11/2000
[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 HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17
18 #ifdef _IBMR2
19 #include <sys/machine.h>
20 #endif /*_IBMR2*/
21
22 #ifdef _ISOC9X_SOURCE
23 #include <inttypes.h>
24 typedef uint8_t        u_int8_t;
25 typedef uint16_t       u_int16_t;
26 typedef uint32_t       u_int32_t;
27 typedef uint64_t       u_int64_t;
28 #else
29
30 /* handle sunos and solaris */
31 #ifdef sun
32 #ifdef BSD4_3
33 #include <sys/bitypes.h>
34 #else
35 /* solaris and sunos don't consistently define u_int*_t. */
36 typedef unsigned char      u_int8_t;
37 typedef unsigned short     u_int16_t;
38 typedef unsigned int       u_int32_t;
39 typedef int                int32_t;
40 #endif
41
42 typedef unsigned long long u_int64_t;
43
44 #ifndef _SSIZE_T
45 #define _SSIZE_T
46 typedef int ssize_t;
47 #endif /* ssize_t */
48
49 #else /* sun */
50
51 /* luckily ultrix is dead. as a result, we know what the sizes of
52  * various types are forever. this makes some assumptions about integer
53  * sizes. */
54 #if defined (ultrix) || defined(HAVE_32BIT_LONGS) || defined(HAVE_64BIT_LONGS)
55 typedef unsigned char  u_int8_t;
56 typedef unsigned short u_int16_t;
57 typedef unsigned int   u_int32_t;
58 typedef int            int32_t;
59 #endif
60
61 #ifdef ultrix
62 typedef int            ssize_t;
63 #endif
64
65 #ifdef HAVE_64BIT_LONGS
66 typedef unsigned long u_int64_t;
67 #else
68 /* check for long long support. currently, i assume that if 64-bit
69  * ints exist that their made available via long long */
70 #ifdef linux
71 #include <endian.h> /* i think this is here for libc4 */
72 #else 
73 #if defined(HAVE_32BIT_LONGS) && !(defined(BSD4_4) || \
74                                   defined(NO_LARGE_VOL_SUPPORT))
75 typedef unsigned long long  u_int64_t;
76 #endif
77 #endif /* linux */
78 #endif /* HAVE_64BIT_LONGS */
79 #endif /* sun */
80 #endif /* ISOC9X */
81
82 # ifndef BYTE_ORDER
83 #define LITTLE_ENDIAN   1234
84 #define BIG_ENDIAN      4321
85 #define PDP_ENDIAN      3412
86
87 #ifdef sun
88 #if defined(i386) || defined(_LITTLE_ENDIAN)
89 #define BYTE_ORDER      LITTLE_ENDIAN
90 #else /*i386*/
91 #define BYTE_ORDER      BIG_ENDIAN
92 #endif /*i386*/
93 #else
94 #ifdef MIPSEB
95 #define BYTE_ORDER      BIG_ENDIAN
96 #else
97 #ifdef MIPSEL
98 #define BYTE_ORDER      LITTLE_ENDIAN
99 #else
100 #error Like, what is your byte order, man?
101 #endif /*MIPSEL*/
102 #endif /*MIPSEB*/
103 #endif /*sun*/
104 # endif /*BYTE_ORDER*/
105
106 # ifndef ntohl
107 # if defined( sun ) || defined( ultrix ) || defined( _IBMR2 )
108 #if BYTE_ORDER == BIG_ENDIAN
109 #define ntohl(x)        (x)
110 #define ntohs(x)        (x)
111 #define htonl(x)        (x)
112 #define htons(x)        (x)
113
114 #else
115 #if defined( mips ) && defined( KERNEL )
116 #define ntohl(x)        nuxi_l(x)
117 #define ntohs(x)        nuxi_s(x)
118 #define htonl(x)        nuxi_l(x)
119 #define htons(x)        nuxi_s(x)
120
121 #else /*mips KERNEL*/
122
123 #if !( defined( sun ) && defined( i386 ))
124 unsigned short ntohs(), htons();
125 unsigned int  ntohl(), htonl();
126 #endif
127
128 #endif /*mips KERNEL*/
129 #endif /*BYTE_ORDER*/
130 # endif /*sun ultrix _IBMR2*/
131 # endif /*ntohl*/
132
133 #  endif /*_ATALK_ENDIAN_H_*/