source: trunk/third/xntp/util/byteorder.c @ 10832

Revision 10832, 864 bytes checked in by brlewis, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10831, which included commits to RCS files with non-trunk default branches.
RevLine 
[10831]1/*
2 * This works on:
3 *   Crays
4 *   Conven
5 *   sparc's
6 *   Dec mip machines
7 *   Dec alpha machines
8 *   RS6000
9 *   SGI's
10 */
11
12#include <stdio.h>
13main()
14{
15    int i;
16    int big;
17    union {
18        unsigned long l;
19        char c[sizeof(long)];
20    } u;
21
22#if defined(LONG8)
23    u.l = (((long)0x08070605) << 32) | (long)0x04030201;
24#else
25    u.l = 0x04030201;
26#endif
27    if (sizeof(long) > 4) {
28        if (u.c[0] == 0x08) big = 1;
29        else                big = 0;
30    } else {
31        if (u.c[0] == 0x04) big = 1;
32        else                big = 0;
33    }
34    for (i=0; i< sizeof(long); i++) {
35        if (big == 1 && (u.c[i] == (sizeof(long) - i))) {
36                continue;
37        } else if (big == 0 && (u.c[i] == (i+1))) {
38                continue;
39        } else {
40             big = -1;
41             break;
42        }
43    }
44
45    if (big == 1) {
46        printf("XNTP_BIG_ENDIAN\n");
47    } else if (big == 0) {
48        printf("XNTP_LITTLE_ENDIAN\n");
49    }
50  exit(0);
51}
52
Note: See TracBrowser for help on using the repository browser.