]> arthur.barton.de Git - netatalk.git/blob - sys/netatalk/endian.h
340f5ea17794b05f74e33e52e725a7de98f3adbe
[netatalk.git] / sys / netatalk / endian.h
1 /*
2  * $Id: endian.h,v 1.7 2001-12-15 12:13:10 srittau 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 typedef unsigned char  u_int8_t;
61 typedef unsigned short u_int16_t;
62 typedef unsigned int   u_int32_t;
63 typedef int            int32_t;
64 #endif /* ultrix || HAVE_32BIT_LONGS || HAVE_64BIT_LONGS */
65
66 #ifdef ultrix
67 typedef int            ssize_t;
68 #endif /* ultrix */
69
70 #ifdef HAVE_64BIT_LONGS
71 typedef unsigned long u_int64_t;
72 #else /* HAVE_64BIT_LONGS */
73 /* check for long long support. currently, i assume that if 64-bit
74  * ints exist that their made available via long long */
75 #ifdef linux
76 #include <endian.h> /* i think this is here for libc4 */
77 #else /* linux */
78 #if defined(HAVE_32BIT_LONGS) && !(defined(BSD4_4) || \
79                                   defined(NO_LARGE_VOL_SUPPORT))
80 typedef unsigned long long  u_int64_t;
81 #endif /* HAVE_32BIT_LONGS || !BSD4_4 || NO_LARGE_VOL_SUPPORT */
82 #endif /* linux */
83 #endif /* HAVE_64BIT_LONGS */
84 #endif /* sun */
85 #endif /* ISOC9X */
86
87 # ifndef BYTE_ORDER
88 #define LITTLE_ENDIAN   1234
89 #define BIG_ENDIAN      4321
90 #define PDP_ENDIAN      3412
91
92
93 #if defined(WORDS_BIGENDIAN) || defined(_BIG_ENDIAN)
94 #define BYTE_ORDER      BIG_ENDIAN
95 #else
96 #define BYTE_ORDER      LITTLE_ENDIAN
97 #endif /* WORDS_BIGENDIAN */
98
99 # ifndef ntohl
100 # if defined( sun ) || defined( ultrix ) || defined( _IBMR2 )
101 #if BYTE_ORDER == BIG_ENDIAN
102 #define ntohl(x)        (x)
103 #define ntohs(x)        (x)
104 #define htonl(x)        (x)
105 #define htons(x)        (x)
106
107 #else /* BYTE_ORDER == BIG_ENDIAN */
108 #if defined( mips ) && defined( KERNEL )
109 #define ntohl(x)        nuxi_l(x)
110 #define ntohs(x)        nuxi_s(x)
111 #define htonl(x)        nuxi_l(x)
112 #define htons(x)        nuxi_s(x)
113
114 #else /* mips && KERNEL */
115
116 #if !( defined( sun ) && defined( i386 ))
117 unsigned short ntohs(), htons();
118 unsigned int  ntohl(), htonl();
119 #endif /* ! ( sun && i386 ) */
120
121 #endif /* mips && KERNEL */
122 #endif /* BYTE_ORDER == BIGENDIAN*/
123 # endif /* sun ultrix _IBMR2 */
124 # endif /* ntohl */
125 #endif /* BYTE_ORDER */
126
127 #endif /* _ATALK_ENDIAN_H_ */
128