1 |
wdelano |
22 |
/*===========================================================================* |
2 |
|
|
* byteorder.h * |
3 |
|
|
* * |
4 |
|
|
* stuff to handle different byte order * |
5 |
|
|
* * |
6 |
|
|
*===========================================================================*/ |
7 |
|
|
|
8 |
|
|
/* |
9 |
|
|
* Copyright (c) 1995 The Regents of the University of California. |
10 |
|
|
* All rights reserved. |
11 |
|
|
* |
12 |
|
|
* Permission to use, copy, modify, and distribute this software and its |
13 |
|
|
* documentation for any purpose, without fee, and without written agreement is |
14 |
|
|
* hereby granted, provided that the above copyright notice and the following |
15 |
|
|
* two paragraphs appear in all copies of this software. |
16 |
|
|
* |
17 |
|
|
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR |
18 |
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT |
19 |
|
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF |
20 |
|
|
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
21 |
|
|
* |
22 |
|
|
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, |
23 |
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
24 |
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
25 |
|
|
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO |
26 |
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
27 |
|
|
*/ |
28 |
|
|
|
29 |
|
|
/* |
30 |
|
|
* $Header: /u/smoot/md/mpeg_encode/headers/RCS/byteorder.h,v 1.3 1995/01/19 23:54:39 eyhung Exp $ |
31 |
|
|
* $Log: byteorder.h,v $ |
32 |
|
|
* Revision 1.3 1995/01/19 23:54:39 eyhung |
33 |
|
|
* Changed copyrights |
34 |
|
|
* |
35 |
|
|
* Revision 1.3 1995/01/19 23:54:39 eyhung |
36 |
|
|
* Changed copyrights |
37 |
|
|
* |
38 |
|
|
* Revision 1.2 1994/11/12 02:12:15 keving |
39 |
|
|
* nothing |
40 |
|
|
* |
41 |
|
|
* Revision 1.1 1993/07/22 22:24:23 keving |
42 |
|
|
* nothing |
43 |
|
|
* |
44 |
|
|
*/ |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
#include "general.h" |
48 |
|
|
|
49 |
wdelano |
23 |
#ifdef WIN32 |
50 |
|
|
#define FORCE_LITTLE_ENDIAN |
51 |
|
|
#endif |
52 |
wdelano |
22 |
|
53 |
|
|
#ifdef FORCE_BIG_ENDIAN |
54 |
|
|
/* leave byte order as it is */ |
55 |
|
|
#define htonl(x) (x) |
56 |
|
|
#define ntohl(x) (x) |
57 |
|
|
#define htons(x) (x) |
58 |
|
|
#define ntohs(x) (x) |
59 |
|
|
#else |
60 |
|
|
#ifdef FORCE_LITTLE_ENDIAN |
61 |
|
|
/* need to reverse byte order */ |
62 |
|
|
/* note -- we assume here that htonl is called on a variable, not a |
63 |
|
|
* constant; thus, this is not for general use, but works with bitio.c |
64 |
|
|
*/ |
65 |
|
|
#define htonl(x) \ |
66 |
|
|
((((unsigned char *)(&x))[0] << 24) | \ |
67 |
|
|
(((unsigned char *)(&x))[1] << 16) | \ |
68 |
|
|
(((unsigned char *)(&x))[2] << 8) | \ |
69 |
|
|
(((unsigned char *)(&x))[3])) |
70 |
|
|
#define ntohl(x) htonl(x) |
71 |
|
|
#define htons(x) \ |
72 |
|
|
((((unsigned char *)(&x))[0] << 8) | \ |
73 |
|
|
((unsigned char *)(&x))[1]) |
74 |
|
|
#define ntohs(x) htons(x) |
75 |
|
|
#else |
76 |
|
|
/* let in.h handle it, if possible */ |
77 |
|
|
#include <sys/types.h> |
78 |
|
|
#include <netinet/in.h> |
79 |
|
|
#endif /* FORCE_LITTLE_ENDIAN */ |
80 |
|
|
#endif /* FORCE_BIG_ENDIAN */ |