File: endian.h

package info (click to toggle)
netatalk 2.0.3-4
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 9,004 kB
  • ctags: 6,109
  • sloc: ansic: 67,633; sh: 8,424; perl: 1,187; makefile: 1,001
file content (128 lines) | stat: -rw-r--r-- 3,246 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * $Id: endian.h,v 1.7 2001/12/15 12:13:10 srittau Exp $
 *
 * Copyright (c) 1990,1991 Regents of The University of Michigan.
 * All Rights Reserved. See COPYRIGHT.
 *
 * This file handles both byte ordering and integer sizes.
 */

#ifndef _ATALK_ENDIAN_H_
#define _ATALK_ENDIAN_H_

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#include <sys/types.h>
#include <netinet/in.h>

#ifdef _IBMR2
#include <sys/machine.h>
#endif /*_IBMR2*/

#ifdef _ISOC9X_SOURCE
#include <inttypes.h>
#ifndef __BIT_TYPES_DEFINED__
#define __BIT_TYPES_DEFINED__
typedef uint8_t        u_int8_t;
typedef uint16_t       u_int16_t;
typedef uint32_t       u_int32_t;
typedef uint64_t       u_int64_t;
#endif /* ! __BIT_TYPES_DEFINED__ */
#else

/* handle sunos and solaris */
#ifdef sun
#ifdef BSD4_3
#include <sys/bitypes.h>
#else /* BSD4_3 */
/* solaris and sunos don't consistently define u_int*_t. */
typedef unsigned char      u_int8_t;
typedef unsigned short     u_int16_t;
typedef unsigned int       u_int32_t;
typedef int                int32_t;
#endif /* BSD4_3 */

typedef unsigned long long u_int64_t;

#ifndef _SSIZE_T
#define _SSIZE_T
typedef int ssize_t;
#endif /* ssize_t */

#else /* sun */

/* luckily ultrix is dead. as a result, we know what the sizes of
 * various types are forever. this makes some assumptions about integer
 * sizes. */
#if defined (ultrix) || defined(HAVE_32BIT_LONGS) || defined(HAVE_64BIT_LONGS)
typedef unsigned char  u_int8_t;
typedef unsigned short u_int16_t;
typedef unsigned int   u_int32_t;
typedef int            int32_t;
#endif /* ultrix || HAVE_32BIT_LONGS || HAVE_64BIT_LONGS */

#ifdef ultrix
typedef int            ssize_t;
#endif /* ultrix */

#ifdef HAVE_64BIT_LONGS
typedef unsigned long u_int64_t;
#else /* HAVE_64BIT_LONGS */
/* check for long long support. currently, i assume that if 64-bit
 * ints exist that their made available via long long */
#ifdef linux
#include <endian.h> /* i think this is here for libc4 */
#else /* linux */
#if defined(HAVE_32BIT_LONGS) && !(defined(BSD4_4) || \
				  defined(NO_LARGE_VOL_SUPPORT))
typedef unsigned long long  u_int64_t;
#endif /* HAVE_32BIT_LONGS || !BSD4_4 || NO_LARGE_VOL_SUPPORT */
#endif /* linux */
#endif /* HAVE_64BIT_LONGS */
#endif /* sun */
#endif /* ISOC9X */

# ifndef BYTE_ORDER
#define LITTLE_ENDIAN	1234
#define BIG_ENDIAN	4321
#define PDP_ENDIAN	3412


#if defined(WORDS_BIGENDIAN) || defined(_BIG_ENDIAN)
#define BYTE_ORDER	BIG_ENDIAN
#else
#define BYTE_ORDER	LITTLE_ENDIAN
#endif /* WORDS_BIGENDIAN */

# ifndef ntohl
# if defined( sun ) || defined( ultrix ) || defined( _IBMR2 )
#if BYTE_ORDER == BIG_ENDIAN
#define ntohl(x)	(x)
#define ntohs(x)	(x)
#define htonl(x)	(x)
#define htons(x)	(x)

#else /* BYTE_ORDER == BIG_ENDIAN */
#if defined( mips ) && defined( KERNEL )
#define	ntohl(x)	nuxi_l(x)
#define	ntohs(x)	nuxi_s(x)
#define	htonl(x)	nuxi_l(x)
#define	htons(x)	nuxi_s(x)

#else /* mips && KERNEL */

#if !( defined( sun ) && defined( i386 ))
unsigned short ntohs(), htons();
unsigned int  ntohl(), htonl();
#endif /* ! ( sun && i386 ) */

#endif /* mips && KERNEL */
#endif /* BYTE_ORDER == BIGENDIAN*/
# endif /* sun ultrix _IBMR2 */
# endif /* ntohl */
#endif /* BYTE_ORDER */

#endif /* _ATALK_ENDIAN_H_ */