1 /* $NetBSD: byteorder.c,v 1.5 2020/05/25 20:47:37 christos Exp $ */ 2 3 /* 4 * This works on: 5 * Crays 6 * Conven 7 * sparc's 8 * Dec mip machines 9 * Dec alpha machines 10 * RS6000 11 * SGI's 12 */ 13 14 #include <stdio.h> 15 16 int main(int argc,char * argv[])17main( 18 int argc, 19 char *argv[] 20 ) 21 { 22 int i; 23 int big; 24 union { 25 unsigned long l; 26 char c[sizeof(long)]; 27 } u; 28 29 #if defined(LONG8) 30 u.l = (((long)0x08070605) << 32) | (long)0x04030201; 31 #else 32 u.l = 0x04030201; 33 #endif 34 if (sizeof(long) > 4) { 35 if (u.c[0] == 0x08) big = 1; 36 else big = 0; 37 } else { 38 if (u.c[0] == 0x04) big = 1; 39 else big = 0; 40 } 41 for (i=0; i< sizeof(long); i++) { 42 if (big == 1 && (u.c[i] == (sizeof(long) - i))) { 43 continue; 44 } else if (big == 0 && (u.c[i] == (i+1))) { 45 continue; 46 } else { 47 big = -1; 48 break; 49 } 50 } 51 52 if (big == 1) { 53 printf("XNTP_BIG_ENDIAN\n"); 54 } else if (big == 0) { 55 printf("XNTP_LITTLE_ENDIAN\n"); 56 } 57 exit(0); 58 } 59