Browse Source

Add Readme; determine endianness function and a test for it

master
Gitea 2 years ago
parent
commit
cf95c3873f
  1. 2
      .gitignore
  2. 16
      README.md
  3. 13
      src/endian/endian.c
  4. BIN
      testing/test
  5. 6
      testing/test.c

2
.gitignore vendored

@ -1,2 +1,4 @@
build/ build/
bin/ bin/
testing/test
auxilib

16
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 !

13
src/endian/endian.c

@ -12,6 +12,19 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
#include <stdint.h> #include <stdint.h>
// 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) { uint16_t swap_endian16(uint16_t num) {
return (uint16_t) return (uint16_t)
( (

BIN
testing/test

Binary file not shown.

6
testing/test.c

@ -75,6 +75,12 @@ int test_img() {
} }
int test_endian() { 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 // 01100001 10101000
const uint16_t test_num16 = 25000; const uint16_t test_num16 = 25000;
// 10101000 01100001 // 10101000 01100001

Loading…
Cancel
Save