|
|
1.1 root 1: /* xpendian.h */
2:
3: /* Macros to convert integer "endianness" */
4:
5: /* $Id: xpendian.h,v 1.4 2004/08/26 21:51:54 rswindell Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This library is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU Lesser General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU Lesser General Public License for more details: lgpl.txt or *
18: * http://www.fsf.org/copyleft/lesser.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #ifndef _XPENDIAN_H
39: #define _XPENDIAN_H
40:
41: /************************/
42: /* byte-swapping macros */
43: /************************/
44: #define BYTE_SWAP_16(x) ((((short)(x)&0xff00)>>8) | (((short)(x)&0x00ff)<<8))
45: #define BYTE_SWAP_32(x) ((((long)(x)&0xff000000)>>24) | (((long)(x)&0x00ff0000)>>8) | (((long)(x)&0x0000ff00)<<8) | (((long)(x)&0x000000ff)<<24))
46:
47: /* these may need to be updated for > 32-bit platforms */
48: #define BYTE_SWAP_SHORT(x) BYTE_SWAP_16(x)
49: #define BYTE_SWAP_LONG(x) BYTE_SWAP_32(x)
50:
51: /* auto-detect integer size */
52: #define BYTE_SWAP_INT(x) (sizeof(x)==sizeof(short) ? BYTE_SWAP_SHORT(x) : sizeof(x)==sizeof(long) ? BYTE_SWAP_LONG(x) : (x))
53:
54: /********************************/
55: /* Architecture-specific macros */
56: /********************************/
57: #ifdef __BIG_ENDIAN__ /* e.g. Motorola */
58:
59: #define BE_SHORT(x) (x)
60: #define BE_LONG(x) (x)
61: #define BE_INT(x) (x)
62: #define LE_SHORT(x) BYTE_SWAP_SHORT(x)
63: #define LE_LONG(x) BYTE_SWAP_LONG(x)
64: #define LE_INT(x) BYTE_SWAP_INT(x)
65:
66: #else /* Little Endian (e.g. Intel) */
67:
68: #define LE_SHORT(x) (x)
69: #define LE_LONG(x) (x)
70: #define LE_INT(x) (x)
71: #define BE_SHORT(x) BYTE_SWAP_SHORT(x)
72: #define BE_LONG(x) BYTE_SWAP_LONG(x)
73: #define BE_INT(x) BYTE_SWAP_INT(x)
74:
75: #endif
76:
77: #endif /* Don't add anything after this line */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.