diff --git a/.gitignore b/.gitignore index 4e9c87a..7db15cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ build/ -bin/ \ No newline at end of file +bin/ +testing/test +auxilib \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..49e1ec0 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# AUXILIB +## A collection of various drop-in helper functions; AKA auxiliary C/С++ library + +# Build +`make lib` or, if you don't have make or don't use gcc - translate the "lib" recipe into what works best for you, ie: +`gcc -Wall -Werror -O2 -shared src/*/*.c -o auxilib` + +# Use +Either +- Compile the library as a whole separately and use that +or +- Copy file(s) with needed functionality to your project + +# License +Currently auxilib uses MIT license. +You're free to do anything you want, just don't forget to include a notice ! \ No newline at end of file diff --git a/src/endian/endian.c b/src/endian/endian.c index e8738f3..8bdeb30 100644 --- a/src/endian/endian.c +++ b/src/endian/endian.c @@ -12,6 +12,19 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I #include +// Determine this machine's endianness. Returns 0 in case it is of Big-Endian type, 1 - Little-Endian +int endianness() { + // 00000000 00000001 + int16_t n = 1; + if (*(uint8_t*) &n == 1) { + // 00000001 + return 1; + } else { + // 00000000 + return 0; + } +} + uint16_t swap_endian16(uint16_t num) { return (uint16_t) ( diff --git a/testing/test b/testing/test index 76f94ca..60e9a5e 100755 Binary files a/testing/test and b/testing/test differ diff --git a/testing/test.c b/testing/test.c index 0ca8632..a7979aa 100644 --- a/testing/test.c +++ b/testing/test.c @@ -75,6 +75,12 @@ int test_img() { } int test_endian() { + if (endianness() == 0) { + printf("[INFO] This machine is determined to be of Big-Endian type; Test's failed if that's not the case\n"); + } else { + printf("[INFO] This machine is determined to be of Little-Endian type; Test's failed if that's not the case\n"); + } + // 01100001 10101000 const uint16_t test_num16 = 25000; // 10101000 01100001