OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / pluto / endian.h
1 #ifndef __ENDIAN__H__
2 #define __ENDIAN__H__
3 /* byte-order stuff
4  * Copyright (C) 1998, 1999  D. Hugh Redelmeier.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation; either version 2 of the License, or (at your
9  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * for more details.
15  *
16  * RCSID $Id: endian.h,v 1.5 1999/12/13 00:40:51 dhr Exp $
17  */
18
19 /* sets BYTE_ORDER, LITTLE_ENDIAN, and BIG_ENDIAN */
20
21 #if defined(__OpenBSD__) || defined(__NetBSD__)
22 # include <machine/endian.h>
23 #elif linux
24 # if defined(i386) && !defined(__i386__)
25 #  define __i386__ 1
26 #  define MYHACKFORTHIS 1
27 # endif
28 # include_next <endian.h>
29 # ifdef USE_ASM_BYTEORDER   /* kernel's <asm/byteorder.h> clashes with glibc's <netinet/in.h> */
30    /* The problem (in RedHat 5.0) is the typing of the "longs" (32-bit values)
31     * in the [nh]to[hn]l functions:
32     * - <asm/byteorder.h> uses unsigned long
33     * - <netinet/in.h> uses u_int32_t which is unsigned int
34     * Since 64-bit machines are supported, <asm/byteorder.h> should be changed.
35     * For now, we simply don't use <asm/byteorder.h>.
36     */
37 #  include <asm/byteorder.h>
38 # endif
39 # ifdef MYHACKFORTHIS
40 #  undef __i386__
41 #  undef MYHACKFORTHIS
42 # endif
43 #elif !(defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) && defined(BYTE_ORDER))
44  /* we don't know how to do this, so we require the macros to be defined
45   * with compiler flags:
46   *    -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=BIG_ENDIAN
47   * or -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=LITTLE_ENDIAN
48   * Thse match the GNU definitions
49   */
50 # include <sys/endian.h>
51 #endif
52
53 #ifndef BIG_ENDIAN
54  #error BIG_ENDIAN must be defined
55 #endif
56
57 #ifndef LITTLE_ENDIAN
58  #error LITTLE_ENDIAN must be defined
59 #endif
60
61 #ifndef BYTE_ORDER
62  #error BYTE_ORDER must be defined
63 #endif
64
65 #endif /*__ENDIAN__H__ */