Commit | Line | Data |
---|---|---|
c627d613 AT |
1 | /* |
2 | simple byteorder handling | |
3 | Copyright (C) Andrew Tridgell 1992-1995 | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | */ | |
19 | ||
20 | #undef CAREFUL_ALIGNMENT | |
21 | ||
22 | /* we know that the x86 can handle misalignment and has the "right" | |
23 | byteorder */ | |
24 | #ifdef __i386__ | |
25 | #define CAREFUL_ALIGNMENT 0 | |
26 | #endif | |
27 | ||
28 | #ifndef CAREFUL_ALIGNMENT | |
29 | #define CAREFUL_ALIGNMENT 1 | |
30 | #endif | |
31 | ||
32 | #define CVAL(buf,pos) (((unsigned char *)(buf))[pos]) | |
33 | #define PVAL(buf,pos) ((unsigned)CVAL(buf,pos)) | |
34 | #define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) | |
35 | ||
36 | ||
37 | #if CAREFUL_ALIGNMENT | |
38 | #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) | |
39 | #define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16) | |
40 | #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) | |
41 | #define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16)) | |
42 | #define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val))) | |
43 | #else | |
44 | /* this handles things for architectures like the 386 that can handle | |
45 | alignment errors */ | |
46 | /* | |
47 | WARNING: This section is dependent on the length of int32 | |
48 | being correct. set CAREFUL_ALIGNMENT if it is not. | |
49 | */ | |
50 | #define IVAL(buf,pos) (*(uint32 *)((char *)(buf) + (pos))) | |
51 | #define SIVAL(buf,pos,val) IVAL(buf,pos)=((uint32)(val)) | |
52 | #endif | |
53 | ||
54 |