File: dn_endian.h

package info (click to toggle)
latd 1.30
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,352 kB
  • ctags: 1,046
  • sloc: cpp: 8,489; sh: 878; makefile: 85
file content (60 lines) | stat: -rw-r--r-- 1,901 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
/******************************************************************************
    (c) 1998, 2003 Christine Caulfield               christine.caulfield@googlemail.com
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 ******************************************************************************
 */
/* Header file to cope with endian issues */

#if defined(__NetBSD__) || defined(__FreeBSD__)
#include <machine/endian.h>
#define __BYTE_ORDER BYTE_ORDER
#endif

#ifdef __APPLE__
#include <architecture/byte_order.h>
#define __BYTE_ORDER BYTE_ORDER
#endif


#ifndef __BYTE_ORDER
    #error "Can't determine endianness - please inform christine.caulfield@googlemail.com with your distribution and hardware type."
#endif

#if (__BYTE_ORDER == 1234)

  /* It's a VAX or Intel, or some other obscure make :-) */

  /* DECnet is little-endian so these are no-ops */
  #define dn_ntohs(x) (x)
  #define dn_htons(x) (x)

  #define dn_ntohl(x) (x)
  #define dn_htonl(x) (x)

#else
  #if (__BYTE_ORDER == 4321)

    /* It's a SPARC - most likely than not */
 
    #define dn_ntohs(x) ((((x)&0x0ff)<<8) | (((x)&0xff00)>>8))

    #define dn_ntohl(x) ( ((dn_ntohs((x)&0xffff))<<16) |\
			  ((dn_ntohs(((x)>>16)))) )

    #define dn_htonl(x) dn_ntohl(x)
    #define dn_htons(x) dn_ntohs(x)
  #else

    /* it's a PDP??? */
    #error "Unsupported endianness - please inform christine.caulfield@googlemail.com with your distribution and hardware type."
  #endif
#endif