1 /*===========================================================================* 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 50 #ifdef FORCE_BIG_ENDIAN 51 /* leave byte order as it is */ 52 #define htonl(x) (x) 53 #define ntohl(x) (x) 54 #define htons(x) (x) 55 #define ntohs(x) (x) 56 #else 57 #ifdef FORCE_LITTLE_ENDIAN 58 /* need to reverse byte order */ 59 /* note -- we assume here that htonl is called on a variable, not a 60 * constant; thus, this is not for general use, but works with bitio.c 61 */ 62 #define htonl(x) \ 63 ((((unsigned char *)(&x))[0] << 24) | \ 64 (((unsigned char *)(&x))[1] << 16) | \ 65 (((unsigned char *)(&x))[2] << 8) | \ 66 (((unsigned char *)(&x))[3])) 67 #define ntohl(x) htonl(x) 68 #define htons(x) \ 69 ((((unsigned char *)(&x))[0] << 8) | \ 70 ((unsigned char *)(&x))[1]) 71 #define ntohs(x) htons(x) 72 #else 73 /* let in.h handle it, if possible */ 74 #include <sys/types.h> 75 76 // gmsh: for windows 77 #if !defined(WIN32) || defined(__CYGWIN__) 78 #include <netinet/in.h> 79 #else 80 #undef boolean 81 #include <winsock.h> 82 #define boolean int 83 #endif 84 85 #endif /* FORCE_LITTLE_ENDIAN */ 86 #endif /* FORCE_BIG_ENDIAN */ 87