diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-01-27 22:28:19 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-01-27 22:28:19 +0200 |
commit | 919fcbb6ef94a3db918c7d59edb11f61588c8039 (patch) | |
tree | 75d0f0cf5efa136a6b5920156f1fd1d85731df3f | |
parent | aef5ef362d5f0934df44951d20028b64e5529384 (diff) | |
download | meson-919fcbb6ef94a3db918c7d59edb11f61588c8039.zip meson-919fcbb6ef94a3db918c7d59edb11f61588c8039.tar.gz meson-919fcbb6ef94a3db918c7d59edb11f61588c8039.tar.bz2 |
Added endianness check.
-rwxr-xr-x | interpreter.py | 6 | ||||
-rw-r--r-- | test cases/26 endian/builder.txt | 7 | ||||
-rw-r--r-- | test cases/26 endian/prog.c | 26 |
3 files changed, 36 insertions, 3 deletions
diff --git a/interpreter.py b/interpreter.py index 74689a2..a85a0e5 100755 --- a/interpreter.py +++ b/interpreter.py @@ -46,7 +46,7 @@ class Host(InterpreterObject): InterpreterObject.__init__(self) self.methods.update({'pointer_size' : self.get_ptrsize_method, 'name' : self.get_name_method, - 'is_little_endian' : self.is_little_endian_method, + 'is_big_endian' : self.is_big_endian_method, }) def get_ptrsize_method(self, args): @@ -57,8 +57,8 @@ class Host(InterpreterObject): def get_name_method(self, args): return platform.system().lower() - def is_little_endian_method(self, args): - return sys.byteorder == 'little' + def is_big_endian_method(self, args): + return sys.byteorder != 'little' class IncludeDirs(InterpreterObject): def __init__(self, curdir, dirs): diff --git a/test cases/26 endian/builder.txt b/test cases/26 endian/builder.txt new file mode 100644 index 0000000..e3c7b6f --- /dev/null +++ b/test cases/26 endian/builder.txt @@ -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')) diff --git a/test cases/26 endian/prog.c b/test cases/26 endian/prog.c new file mode 100644 index 0000000..261ac0f --- /dev/null +++ b/test cases/26 endian/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; +} |