parent
aef5ef362d
commit
919fcbb6ef
3 changed files with 36 additions and 3 deletions
@ -0,0 +1,7 @@ |
||||
project('endian check', 'c') |
||||
|
||||
if(host.is_big_endian()) |
||||
add_global_arguments('c', '-DIS_BE') |
||||
endif |
||||
|
||||
add_test('endiantest', executable('prog', 'prog.c')) |
@ -0,0 +1,26 @@ |
||||
#include<stdint.h> |
||||
|
||||
int is_big_endian(void) { |
||||
union { |
||||
uint32_t i; |
||||
char c[4]; |
||||
} bint = {0x01020304}; |
||||
|
||||
return bint.c[0] == 1; |
||||
} |
||||
|
||||
|
||||
int main(int argc, char **argv) { |
||||
int is_be_check = is_big_endian(); |
||||
int is_be; |
||||
#ifdef IS_BE |
||||
is_be = 1; |
||||
#else |
||||
is_be = 0; |
||||
#endif |
||||
if(is_be_check && is_be) |
||||
return 0; |
||||
if(!is_be_check && !is_be) |
||||
return 0; |
||||
return 1; |
||||
} |
Loading…
Reference in new issue