From cf95c3873f3507220c87fe7e27da407b3eaf6f74 Mon Sep 17 00:00:00 2001 From: Gitea Date: Mon, 1 Aug 2022 17:47:51 +0300 Subject: [PATCH] Add Readme; determine endianness function and a test for it --- .gitignore | 4 +++- README.md | 16 ++++++++++++++++ src/endian/endian.c | 13 +++++++++++++ testing/test | Bin 21640 -> 21680 bytes testing/test.c | 6 ++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 README.md 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 76f94ca5a4000b39374869ca116e5f3cf02d1ab5..60e9a5e5a116c037aff76ac1fe5f5a10ab331120 100755 GIT binary patch delta 2345 zcmZWrYfKbZ6rLH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