-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendian.h
45 lines (38 loc) · 836 Bytes
/
endian.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef ENDIAN_H
#define ENDIAN_H
/* the main byte-swapping function */
#ifdef __cplusplus
extern "C" {
#endif
extern void changeEndian(void *, int);
#ifdef __cplusplus
}
#endif
/* is it Big or Little endian?? */
#ifdef __alpha
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN
#endif
#endif
#ifdef sgi
#undef LITTLE_ENDIAN
#endif
#ifdef sun
#define BIG_ENDIAN
#endif
#ifdef linux /* not sure if this works .. try gcc -v on a linux machine */
#define LITTLE_ENDIAN
#endif
/* endian-ness macros */
#ifdef LITTLE_ENDIAN
#define toBigEndian(p,s) changeEndian(p,s)
#define toLittleEndian(p,s)
#define fromBigEndian(p,s) changeEndian(p,s)
#define fromLittleEndian(p,s)
#else
#define toBigEndian(p,s)
#define toLittleEndian(p,s) changeEndian(p,s)
#define fromBigEndian(p,s)
#define fromLittleEndian(p,s) changeEndian(p,s)
#endif
#endif