1 /* 2 * This file has been modified for the cdrkit suite. 3 * 4 * The behaviour and appearence of the program code below can differ to a major 5 * extent from the version distributed by the original author(s). 6 * 7 * For details, see Changelog file distributed with the cdrkit package. If you 8 * received this file from another source then ask the distributing person for 9 * a log of modifications. 10 * 11 */ 12 13 /* @(#)intcvt.h 1.4 03/12/29 Copyright 1986-2003 J. Schilling */ 14 /* 15 * Definitions for conversion to/from integer data types of various size. 16 * 17 * Copyright (c) 1986-2003 J. Schilling 18 */ 19 /* 20 * This program is free software; you can redistribute it and/or modify 21 * it under the terms of the GNU General Public License version 2 22 * as published by the Free Software Foundation. 23 * 24 * This program is distributed in the hope that it will be useful, 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 * GNU General Public License for more details. 28 * 29 * You should have received a copy of the GNU General Public License along with 30 * this program; see the file COPYING. If not, write to the Free Software 31 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 32 */ 33 34 #ifndef _INTCVT_H 35 #define _INTCVT_H 36 37 #ifndef _MCONFIG_H 38 #include <mconfig.h> 39 #endif 40 41 #define i_to_2_byte(a, i) (((Uchar *)(a))[0] = ((i) >> 8) & 0xFF,\ 42 ((Uchar *)(a))[1] = (i) & 0xFF) 43 44 #define i_to_3_byte(a, i) (((Uchar *)(a))[0] = ((i) >> 16)& 0xFF,\ 45 ((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\ 46 ((Uchar *)(a))[2] = (i) & 0xFF) 47 48 #define i_to_4_byte(a, i) (((Uchar *)(a))[0] = ((i) >> 24)& 0xFF,\ 49 ((Uchar *)(a))[1] = ((i) >> 16)& 0xFF,\ 50 ((Uchar *)(a))[2] = ((i) >> 8) & 0xFF,\ 51 ((Uchar *)(a))[3] = (i) & 0xFF) 52 53 54 55 #define a_to_byte(a) (((Int8_t *) a)[0]) 56 57 #define a_to_u_byte(a) ((UInt8_t) \ 58 (((Uchar *) a)[0] & 0xFF)) 59 60 #define a_to_u_2_byte(a) ((UInt16_t) \ 61 ((((Uchar *) a)[1] & 0xFF) | \ 62 (((Uchar *) a)[0] << 8 & 0xFF00))) 63 64 #define a_to_2_byte(a) (int)(Int16_t)a_to_u_2_byte(a) 65 66 #define a_to_u_3_byte(a) ((Ulong) \ 67 ((((Uchar *) a)[2] & 0xFF) | \ 68 (((Uchar *) a)[1] << 8 & 0xFF00) | \ 69 (((Uchar *) a)[0] << 16 & 0xFF0000))) 70 71 #define a_to_3_byte(a) a_to_u_3_byte(a) /* XXX Is there a signed version ? */ 72 73 #ifdef __STDC__ 74 # define __TOP_4BYTE 0xFF000000UL 75 #else 76 # define __TOP_4BYTE 0xFF000000 77 #endif 78 79 #define a_to_u_4_byte(a) ((Ulong) \ 80 ((((Uchar*) a)[3] & 0xFF) | \ 81 (((Uchar*) a)[2] << 8 & 0xFF00) | \ 82 (((Uchar*) a)[1] << 16 & 0xFF0000) | \ 83 (((Uchar*) a)[0] << 24 & __TOP_4BYTE))) 84 85 #define a_to_4_byte(a) (long)(Int32_t)a_to_u_4_byte(a) 86 87 /* 88 * Little Endian versions of above macros 89 */ 90 #define li_to_2_byte(a, i) (((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\ 91 ((Uchar *)(a))[0] = (i) & 0xFF) 92 93 #define li_to_3_byte(a, i) (((Uchar *)(a))[2] = ((i) >> 16)& 0xFF,\ 94 ((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\ 95 ((Uchar *)(a))[0] = (i) & 0xFF) 96 97 #define li_to_4_byte(a, i) (((Uchar *)(a))[3] = ((i) >> 24)& 0xFF,\ 98 ((Uchar *)(a))[2] = ((i) >> 16)& 0xFF,\ 99 ((Uchar *)(a))[1] = ((i) >> 8) & 0xFF,\ 100 ((Uchar *)(a))[0] = (i) & 0xFF) 101 102 103 #define la_to_u_2_byte(a) ((UInt16_t) \ 104 ((((Uchar*) a)[0] & 0xFF) | \ 105 (((Uchar*) a)[1] << 8 & 0xFF00))) 106 107 #define la_to_2_byte(a) (int)(Int16_t)la_to_u_2_byte(a) 108 109 #define la_to_u_3_byte(a) ((Ulong) \ 110 ((((Uchar*) a)[0] & 0xFF) | \ 111 (((Uchar*) a)[1] << 8 & 0xFF00) | \ 112 (((Uchar*) a)[2] << 16 & 0xFF0000))) 113 114 #define la_to_3_byte(a) la_to_u_3_byte(a) /* XXX Is there a signed version ? */ 115 116 #define la_to_u_4_byte(a) ((Ulong) \ 117 ((((Uchar*) a)[0] & 0xFF) | \ 118 (((Uchar*) a)[1] << 8 & 0xFF00) | \ 119 (((Uchar*) a)[2] << 16 & 0xFF0000) | \ 120 (((Uchar*) a)[3] << 24 & __TOP_4BYTE))) 121 122 #define la_to_4_byte(a) (long)(Int32_t)la_to_u_4_byte(a) 123 124 #endif /* _INTCVT_H */ 125