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