-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendian.c
37 lines (34 loc) · 956 Bytes
/
endian.c
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
/*
* endian.c:
* Determine platform endianness.
*
* Copyright (c) 2002 . All rights reserved.
* Email: [email protected]; WWW: http://www.ex-parrot.com/~chris/
*
*/
static const char rcsid[] = "$Id: endian.c,v 1.6 2003/11/03 10:40:23 chris Exp $";
#include <stdio.h>
#ifdef USE_SYS_TYPES_H
# include <sys/types.h> /* Solaris etc. */
#else
# include <stdint.h> /* C99 standard. */
#endif
int main(void) {
#if defined(LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN)
printf("#define DRIFTNET_LITTLE_ENDIAN\n");
return 0;
#elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN)
printf("#define DRIFTNET_BIG_ENDIAN\n");
return 0;
#else
uint32_t a = 0;
*((uint8_t*)&a) = 0xff;
if (a == 0xff000000)
printf("#define DRIFTNET_BIG_ENDIAN\n");
else if (a == 0x000000ff)
printf("#define DRIFTNET_LITTLE_ENDIAN\n");
else
return -1; /* don't know. */
#endif /* endianness test */
return 0;
}