summaryrefslogtreecommitdiff
path: root/src/sysdeps/tryendianness.c
blob: 3fa193831114566c35b08ceea5c38c4bd3adc483 (plain)
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
38
39
40
41
42
43
/* ISC license. */

#include <stdio.h>

int main (void)
{
  unsigned long i = 0xdeadbeefUL ;
  if (sizeof(unsigned long) == 4)
    if ((((unsigned char *)(&i))[0] == 0xef)
     && (((unsigned char *)(&i))[1] == 0xbe)
     && (((unsigned char *)(&i))[2] == 0xad)
     && (((unsigned char *)(&i))[3] == 0xde))
      return (puts("little"), 0) ;
    else if ((((unsigned char *)(&i))[0] == 0xde)
     && (((unsigned char *)(&i))[1] == 0xad)
     && (((unsigned char *)(&i))[2] == 0xbe)
     && (((unsigned char *)(&i))[3] == 0xef))
      return (puts("big"), 0) ;
    else return (puts("unknown"), 1) ;
  else if (sizeof(unsigned long) == 8)
    if ((((unsigned char *)(&i))[0] == 0xef)
     && (((unsigned char *)(&i))[1] == 0xbe)
     && (((unsigned char *)(&i))[2] == 0xad)
     && (((unsigned char *)(&i))[3] == 0xde)
     && (((unsigned char *)(&i))[4] == 0x00)
     && (((unsigned char *)(&i))[5] == 0x00)
     && (((unsigned char *)(&i))[6] == 0x00)
     && (((unsigned char *)(&i))[7] == 0x00))
      return (puts("little"), 0) ;
    else if (sizeof(unsigned long) == 8)
      if ((((unsigned char *)(&i))[0] == 0x00)
       && (((unsigned char *)(&i))[1] == 0x00)
       && (((unsigned char *)(&i))[2] == 0x00)
       && (((unsigned char *)(&i))[3] == 0x00)
       && (((unsigned char *)(&i))[4] == 0xde)
       && (((unsigned char *)(&i))[5] == 0xad)
       && (((unsigned char *)(&i))[6] == 0xbe)
       && (((unsigned char *)(&i))[7] == 0xef))
        return (puts("big"), 0) ;
      else return (puts("unknown"), 1) ;
    else return 1 ;
  else return (puts("unknown unsigned long size"), 1) ;
}