1 /*----------------------------------------------------------------------------*/
2 /* Xymon monitor library. */
3 /* */
4 /* Utility program to define endian-ness of the target system. */
5 /* */
6 /* Copyright (C) 2006-2011 Henrik Storner <henrik@storner.dk> */
7 /* */
8 /* This program is released under the GNU General Public License (GPL), */
9 /* version 2. See the file "COPYING" for details. */
10 /* */
11 /*----------------------------------------------------------------------------*/
12
13 static char rcsid[] = "$Id: test-endianness.c 6712 2011-07-31 21:01:52Z storner $";
14
15 #include <string.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19
main(int argc,char ** argv)20 int main(int argc, char **argv)
21 {
22 unsigned int c;
23 unsigned char cbuf[sizeof(c)];
24 int i;
25 int outform = 1;
26
27 if ((argc > 1) && (strcmp(argv[1], "--configh") == 0)) outform = 0;
28
29 for (i=0; (i < sizeof(c)); i++) {
30 cbuf[i] = (i % 2);
31 }
32
33 memcpy(&c, cbuf, sizeof(c));
34
35 if (c == 65537) {
36 /* Big endian */
37 if (outform == 0)
38 printf("#ifndef XYMON_BIG_ENDIAN\n#define XYMON_BIG_ENDIAN\n#endif\n");
39 else
40 printf(" -DXYMON_BIG_ENDIAN");
41 }
42 else if (c == 16777472) {
43 /* Little endian */
44 if (outform == 0)
45 printf("#ifndef XYMON_LITTLE_ENDIAN\n#define XYMON_LITTLE_ENDIAN\n#endif\n");
46 else
47 printf(" -DXYMON_LITTLE_ENDIAN");
48 }
49 else {
50 fprintf(stderr, "UNKNOWN ENDIANNESS! testvalue is %u\n", c);
51 }
52
53 fflush(stdout);
54 return 0;
55 }
56
57