moved endian function to misc.c, added sleep_ms(), changed project structure
Minclude/cutils/cutils.h
| @@ -2,5 +2,5 @@ | |||
|---|---|---|---|
| 2 | 2 | #define CUTILS_H | |
| 3 | 3 | #include <cutils/vector.h> | |
| 4 | 4 | #include <cutils/dyn_string.h> | |
| 5 | - | #include <cutils/cutils_endian.h> | |
| 5 | + | #include <cutils/misc.h> | |
| 6 | 6 | #endif //CUTILS_H | |
Dinclude/cutils/cutils_endian.h-17
| @@ -1,17 +0,0 @@ | |||
|---|---|---|---|
| 1 | - | #ifndef CUTILS_ENDIAN_H | |
| 2 | - | #define CUTILS_ENDIAN_H | |
| 3 | - | #include <stdint.h> | |
| 4 | - | #include <string.h> | |
| 5 | - | ||
| 6 | - | inline uint32_t ntoh32(uint32_t const net) | |
| 7 | - | { | |
| 8 | - | uint8_t data[4]; | |
| 9 | - | memcpy(&data, &net, sizeof(data)); | |
| 10 | - | ||
| 11 | - | return ((uint32_t) data[3] << 0) | |
| 12 | - | | ((uint32_t) data[2] << 8) | |
| 13 | - | | ((uint32_t) data[1] << 16) | |
| 14 | - | | ((uint32_t) data[0] << 24); | |
| 15 | - | } | |
| 16 | - | ||
| 17 | - | #endif //CUTILS_ENDIAN_H | |
Ainclude/cutils/misc.h
| @@ -0,0 +1,15 @@ | |||
|---|---|---|---|
| 1 | + | #ifndef MISC_H | |
| 2 | + | #define MISC_H | |
| 3 | + | #include <stdint.h> | |
| 4 | + | #include <string.h> | |
| 5 | + | ||
| 6 | + | #ifdef __unix__ | |
| 7 | + | #include <unistd.h> | |
| 8 | + | #endif | |
| 9 | + | #ifdef _WIN32 | |
| 10 | + | #include <windows.h> | |
| 11 | + | #endif | |
| 12 | + | ||
| 13 | + | void sleep_ms(int milliseconds); | |
| 14 | + | uint32_t ntoh32(uint32_t const net); | |
| 15 | + | #endif //MISC_H | |
Mmeson.build
| @@ -1,6 +1,7 @@ | |||
|---|---|---|---|
| 1 | 1 | project('cutils', 'c') | |
| 2 | 2 | ||
| 3 | - | CFLAGS = ['-std=c11', '-fstrict-aliasing', '-Wall', '-Wpedantic', '-Wextra'] | |
| 3 | + | WARNINGS = ['-Wall', '-Wpedantic', '-Wextra', '-Wnull-dereference', '-Wshadow', '-Wconversion', '-Wstrict-prototypes', '-Wmissing-prototypes', '-Wcast-qual', '-Wstrict-overflow=5', '-Wunreachable-code', '-Wno-unused-parameter' ] | |
| 4 | + | CFLAGS = ['-std=c11', '-fstrict-aliasing', '-fPIC'] + WARNINGS | |
| 4 | 5 | ||
| 5 | 6 | subdir('include') | |
| 6 | 7 | subdir('src') | |
Msrc/meson.build
| @@ -1,7 +1,7 @@ | |||
|---|---|---|---|
| 1 | - | src = ['vector.c', 'dyn_string.c'] | |
| 1 | + | src = ['vector.c', 'dyn_string.c', 'misc.c'] | |
| 2 | 2 | srctest = src + ['test.c'] | |
| 3 | 3 | ||
| 4 | 4 | lib = shared_library('cutils', src, include_directories : inc) | |
| 5 | - | cutils_dep = declare_dependency(link_with : lib) | |
| 5 | + | cutils_dep = declare_dependency(link_with : lib, include_directories : inc) | |
| 6 | 6 | ||
| 7 | 7 | executable('test_cutils', srctest, include_directories : inc, c_args: CFLAGS ) | |
Asrc/misc.c
| @@ -0,0 +1,22 @@ | |||
|---|---|---|---|
| 1 | + | #include <cutils/misc.h> | |
| 2 | + | ||
| 3 | + | void sleep_ms(int milliseconds) | |
| 4 | + | { | |
| 5 | + | #ifdef __unix__ | |
| 6 | + | usleep(milliseconds * 1000); | |
| 7 | + | #endif | |
| 8 | + | #ifdef _WIN32 | |
| 9 | + | Sleep(milliseconds); | |
| 10 | + | #endif | |
| 11 | + | } | |
| 12 | + | ||
| 13 | + | uint32_t ntoh32(uint32_t const net) | |
| 14 | + | { | |
| 15 | + | uint8_t data[4]; | |
| 16 | + | memcpy(&data, &net, sizeof(data)); | |
| 17 | + | ||
| 18 | + | return ((uint32_t) data[3] << 0) | |
| 19 | + | | ((uint32_t) data[2] << 8) | |
| 20 | + | | ((uint32_t) data[1] << 16) | |
| 21 | + | | ((uint32_t) data[0] << 24); | |
| 22 | + | } | |