bittypes.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005, Condor Engineering, Inc. 
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without 
00006  * modification, are permitted provided that the following conditions 
00007  * are met:
00008  * 
00009  * 1. Redistributions of source code must retain the above copyright 
00010  * notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright 
00012  * notice, this list of conditions and the following disclaimer in the 
00013  * documentation and/or other materials provided with the distribution. 
00014  * 3. Neither the name of the Company (Condor Engineering, Inc) nor the
00015  * names of its contributors may be used to endorse or promote products 
00016  * derived from this software without specific prior written permission. 
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00021  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00022  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00023  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00024  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00025  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00026  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00028  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  * 
00030  */
00031 
00032 /*
00033  * Author: Gianluca Varenni <gianluca.varenni@gmail.com>
00034  */
00035 
00036 #ifndef __BITTYPES_11263484553478329233663473
00037 #define __BITTYPES_11263484553478329233663473
00038 
00039 #include <stdio.h>
00040 
00041 #ifndef TRUE
00042 #define TRUE (1==1)
00043 #define FALSE  (1==0)
00044 #endif /* TRUE */
00045 
00046 #define HOST_BYTE_ORDER         0
00047 #define SWAPPED_HOST_BYTE_ORDER 1
00048 
00049 #define NTAR_ALIGN_XBYTES(a, bytes) (((a) + (bytes-1)) & (~(bytes-1)))  
00050 
00051 #define NTAR_ALIGN_32BITS(a) NTAR_ALIGN_XBYTES(a,4) 
00052 #define NTAR_ALIGN_64BITS(a) NTAR_ALIGN_XBYTES(a,8) 
00053 
00054 #define NTAR_ALIGN_NATIVE(a) NTAR_ALIGN_XBYTES(a, sizeof(void*))
00055 
00056 #ifdef _MSC_VER
00057 
00058 #define NTAR_SWAP_64BITS(a) (\
00059                                 (((a) & 0xFF00000000000000) >> 56) +\
00060                                 (((a) & 0x00FF000000000000) >> 40) +\
00061                                 (((a) & 0x0000FF0000000000) >> 24) +\
00062                                 (((a) & 0x000000FF00000000) >> 8) +\
00063                                 (((a) & 0x00000000FF000000) << 8) +\
00064                                 (((a) & 0x0000000000FF0000) << 24) +\
00065                                 (((a) & 0x000000000000FF00) << 40) +\
00066                                 (((a) & 0x00000000000000FF) << 56)\
00067                             )
00068 
00069 #else
00070 
00071 #define NTAR_SWAP_64BITS(a) (\
00072                                 (((a) & 0xFF00000000000000LL) >> 56) +\
00073                                 (((a) & 0x00FF000000000000LL) >> 40) +\
00074                                 (((a) & 0x0000FF0000000000LL) >> 24) +\
00075                                 (((a) & 0x000000FF00000000LL) >> 8)  +\
00076                                 (((a) & 0x00000000FF000000LL) << 8)  +\
00077                                 (((a) & 0x0000000000FF0000LL) << 24) +\
00078                                 (((a) & 0x000000000000FF00LL) << 40) +\
00079                                 (((a) & 0x00000000000000FFLL) << 56) \
00080                             )
00081 
00082 #endif
00083 
00084 
00085 #define NTAR_SWAP_16BITS(a) ((u_int16)(\
00086                                 (((a) & 0xFF00) >> 8) +\
00087                                 (((a) & 0x00FF) << 8)\
00088                             ))
00089 
00090 #define NTAR_SWAP_32BITS(a) ((u_int32)(\
00091                                 (((a) & 0x000000FF) << 24) +\
00092                                 (((a) & 0x0000FF00) << 8) +\
00093                                 (((a) & 0x00FF0000) >> 8) +\
00094                                 (((a) & 0xFF000000) >> 24)\
00095                             ))
00096 
00097 #if defined(_MSC_VER) || defined(__MINGW32__) 
00098 
00099 typedef unsigned __int64    u_int64;
00100 typedef __int64             int64;
00101 typedef unsigned int        u_int32;
00102 typedef int                 int32;
00103 typedef unsigned short      u_int16;
00104 typedef short               int16;
00105 typedef unsigned char       u_int8;
00106 typedef signed char         int8;
00107 
00108 #else 
00109 
00110 #include <sys/types.h>
00111 
00112 #ifndef u_int32
00113 #define u_int32     u_int32_t
00114 #define int32       int32_t
00115 #define u_int16     u_int16_t
00116 #define int16       int16_t
00117 #define u_int8      u_int8_t
00118 #define int8        int8_t
00119 #define u_int64     u_int64_t
00120 #define int64       int64_t
00121 #endif
00122 
00123 #endif
00124 
00125 typedef int64 ntar_foff;
00126 
00127 #endif /*__BITTYPES_11263484553478329233663473*/

NTAR documentation. Copyright (c) 2004 - 2005 Condor Engineering, Inc. All rights reserved.