From 53d4a9158ae74f254194fa776d7091d8f5edda40 Mon Sep 17 00:00:00 2001 From: Ozan Tezcan Date: Sat, 20 Aug 2022 18:56:21 +0300 Subject: [PATCH] Fix compiler warnings (#95) Fix compiler warnings --- array/README.md | 6 ++--- array/array_example.c | 6 ++--- array/array_test.c | 10 +++---- buffer/README.md | 10 +++---- buffer/buf_example.c | 6 ++--- buffer/buf_test.c | 8 +++--- condition/README.md | 4 +-- condition/cond_test.c | 6 ++--- crc32/crc32_example.c | 2 +- crc32/sc_crc32.c | 2 +- heap/heap_example.c | 2 +- heap/heap_test.c | 2 +- ini/ini_example.c | 2 +- ini/ini_test.c | 36 ++++++++++++------------- linked-list/README.md | 2 +- linked-list/list_example.c | 2 +- linked-list/list_test.c | 2 +- logger/log_example.c | 2 +- logger/log_test.c | 2 +- map/README.md | 4 +-- map/map_example.c | 4 +-- map/map_test.c | 54 +++++++++++++++++++------------------- memory-map/mmap_example.c | 2 +- memory-map/mmap_test.c | 6 ++--- memory-map/sc_mmap.c | 4 +-- mutex/mutex_example.c | 2 +- mutex/mutex_test.c | 2 +- option/README.md | 3 ++- option/option_test.c | 18 ++++++------- perf/perf_example.c | 2 +- perf/sc_perf.c | 6 ++--- perf/sc_perf.h | 6 ++--- queue/queue_test.c | 4 +-- sc/sc_example.c | 2 +- sc/sc_test.c | 10 +++---- signal/README.md | 2 +- signal/sc_signal.c | 2 +- signal/sc_signal.h | 2 +- signal/signal_example.c | 2 +- signal/signal_test.c | 34 ++++++++++++------------ socket/sc_sock.c | 12 ++++----- socket/sc_sock.h | 4 +-- socket/sock_example.c | 2 +- socket/sock_test.c | 37 +++++++++++++------------- string/str_example.c | 2 +- string/str_test.c | 14 +++++----- thread/thread_example.c | 2 +- thread/thread_test.c | 8 +++--- time/sc_time.c | 14 +++++----- time/sc_time.h | 8 +++--- time/time_example.c | 2 +- time/time_test.c | 2 +- timer/sc_timer.c | 2 +- timer/timer_example.c | 6 ++--- timer/timer_test.c | 7 ++--- uri/uri_example.c | 2 +- uri/uri_test.c | 4 +-- 57 files changed, 205 insertions(+), 206 deletions(-) diff --git a/array/README.md b/array/README.md index 1264191..1383a2a 100644 --- a/array/README.md +++ b/array/README.md @@ -13,7 +13,7 @@ #include -void example_str() +void example_str(void) { const char *it; struct sc_array_str arr; @@ -34,7 +34,7 @@ void example_str() sc_array_term(&arr); } -void example_int() +void example_int(void) { struct sc_array_int arr; @@ -51,7 +51,7 @@ void example_int() sc_array_term(&arr); } -int main() +int main(void) { example_int(); example_str(); diff --git a/array/array_example.c b/array/array_example.c index 89c95c8..bc10fc4 100644 --- a/array/array_example.c +++ b/array/array_example.c @@ -2,7 +2,7 @@ #include -void example_str() +void example_str(void) { const char *it; struct sc_array_str arr; @@ -23,7 +23,7 @@ void example_str() sc_array_term(&arr); } -void example_int() +void example_int(void) { struct sc_array_int arr; @@ -40,7 +40,7 @@ void example_int() sc_array_term(&arr); } -int main() +int main(void) { example_int(); example_str(); diff --git a/array/array_test.c b/array/array_test.c index db08f82..2d1af84 100644 --- a/array/array_test.c +++ b/array/array_test.c @@ -4,7 +4,7 @@ #include #include -void example_str() +void example_str(void) { const char *it; struct sc_array_str arr; @@ -25,7 +25,7 @@ void example_str() sc_array_term(&arr); } -void example_int() +void example_int(void) { struct sc_array_int arr; @@ -101,7 +101,7 @@ static void test1(void) sc_array_term(&arr); } -void test2() +void test2(void) { int val; struct sc_array_int arr; @@ -156,7 +156,7 @@ void test2() sc_array_term(&arr); } -void bounds_test() +void bounds_test(void) { int total = 0; int val; @@ -225,7 +225,7 @@ void *__wrap_realloc(void *p, size_t n) return __real_realloc(p, n); } -void fail_test() +void fail_test(void) { int tmp; int total = 0; diff --git a/buffer/README.md b/buffer/README.md index 8bc98b8..50fb1d2 100644 --- a/buffer/README.md +++ b/buffer/README.md @@ -17,7 +17,7 @@ #include "sc_buf.h" #include -void basic() +void basic(void) { struct sc_buf buf; sc_buf_init(&buf, 1024); @@ -33,7 +33,7 @@ void basic() sc_buf_term(&buf); } -void error_check() +void error_check(void) { uint32_t val, val2; struct sc_buf buf; @@ -52,7 +52,7 @@ void error_check() sc_buf_term(&buf); } -int main() +int main(void) { basic(); error_check(); @@ -72,7 +72,7 @@ int main() #include "sc_buf.h" #include -int main() +int main(void) { uint32_t val, val2; struct sc_buf buf; @@ -100,7 +100,7 @@ int main() #include "sc_buf.h" #include -int main() +int main(void) { uint32_t val; struct sc_buf buf; diff --git a/buffer/buf_example.c b/buffer/buf_example.c index 9985bd4..8b41d2d 100644 --- a/buffer/buf_example.c +++ b/buffer/buf_example.c @@ -2,7 +2,7 @@ #include -void basic() +void basic(void) { struct sc_buf buf; sc_buf_init(&buf, 1024); @@ -18,7 +18,7 @@ void basic() sc_buf_term(&buf); } -void error_check() +void error_check(void) { uint32_t val, val2; struct sc_buf buf; @@ -38,7 +38,7 @@ void error_check() sc_buf_term(&buf); } -int main() +int main(void) { basic(); error_check(); diff --git a/buffer/buf_test.c b/buffer/buf_test.c index 473f15d..a194cc1 100644 --- a/buffer/buf_test.c +++ b/buffer/buf_test.c @@ -4,7 +4,7 @@ #include #include -void test1() +void test1(void) { const char *xstr; struct sc_buf buf, buf2; @@ -257,7 +257,7 @@ void test1() sc_buf_term(&buf); } -void test2() +void test2(void) { unsigned char tmp[32]; struct sc_buf buf; @@ -410,7 +410,7 @@ int __wrap_vsnprintf(char *str, size_t size, const char *format, va_list ap) return fail_vsnprintf_value; } -void fail_test() +void fail_test(void) { int tmp; unsigned char *p; @@ -622,7 +622,7 @@ void fail_test() } #endif -int main() +int main(void) { test1(); test2(); diff --git a/condition/README.md b/condition/README.md index 4218d92..e0706aa 100644 --- a/condition/README.md +++ b/condition/README.md @@ -16,14 +16,14 @@ #include -int main() +int main(void) { struct sc_cond cond; sc_cond_init(&cond); // Init once sc_cond_signal(&cond, "test"); // Call this on thread-1 - char* p = sc_cond_wait(&cond); // Call this on another thread. + char *p = sc_cond_wait(&cond); // Call this on another thread. printf("%s \n", p); // Prints "test" diff --git a/condition/cond_test.c b/condition/cond_test.c index 43ca310..5b68fec 100644 --- a/condition/cond_test.c +++ b/condition/cond_test.c @@ -241,7 +241,7 @@ int __wrap_pthread_cond_destroy(pthread_cond_t *c) return -1; } -void fail_test() +void fail_test(void) { struct sc_cond cond; @@ -285,7 +285,7 @@ void fail_test() } #endif -void test1() +void test1(void) { struct sc_cond cond; struct sc_thread thread1; @@ -322,7 +322,7 @@ void test1() assert(sc_cond_term(&cond) == 0); } -int main() +int main(void) { test1(); fail_test(); diff --git a/crc32/crc32_example.c b/crc32/crc32_example.c index 5b8fa45..b84ac8a 100644 --- a/crc32/crc32_example.c +++ b/crc32/crc32_example.c @@ -2,7 +2,7 @@ #include -int main() +int main(void) { uint32_t crc; const uint8_t buf[100] = {0}; diff --git a/crc32/sc_crc32.c b/crc32/sc_crc32.c index 58e750d..705a790 100644 --- a/crc32/sc_crc32.c +++ b/crc32/sc_crc32.c @@ -433,7 +433,7 @@ uint32_t sc_crc32(uint32_t crc, const uint8_t *buf, uint32_t len) #endif } -void sc_crc32_init() +void sc_crc32_init(void) { #ifdef HAVE_CRC32C crc32_init_hw(); diff --git a/heap/heap_example.c b/heap/heap_example.c index e709add..9b82235 100644 --- a/heap/heap_example.c +++ b/heap/heap_example.c @@ -2,7 +2,7 @@ #include -int main() +int main(void) { struct data { int priority; diff --git a/heap/heap_test.c b/heap/heap_test.c index 8b2b577..062f4c3 100644 --- a/heap/heap_test.c +++ b/heap/heap_test.c @@ -244,7 +244,7 @@ void fail_test() } #endif -int main() +int main(void) { example(); fail_test(); diff --git a/ini/ini_example.c b/ini/ini_example.c index 231bd7b..e8842e4 100644 --- a/ini/ini_example.c +++ b/ini/ini_example.c @@ -46,7 +46,7 @@ void string_example(void) assert(rc == 0); } -int main() +int main(void) { string_example(); file_example(); diff --git a/ini/ini_test.c b/ini/ini_test.c index 568c33a..36a2998 100644 --- a/ini/ini_test.c +++ b/ini/ini_test.c @@ -42,7 +42,7 @@ int cb2(void *arg, int line, const char *section, const char *key, return 0; } -void test2() +void test2(void) { int rc; int count = 0; @@ -70,7 +70,7 @@ int cb3(void *arg, int line, const char *section, const char *key, return 0; } -void test3() +void test3(void) { int rc; int count = 0; @@ -103,7 +103,7 @@ int cb4(void *arg, int line, const char *section, const char *key, return 0; } -void test4() +void test4(void) { int rc; int count = 0; @@ -141,7 +141,7 @@ int cb5(int line, void *arg, const char *section, const char *key, return 0; } -void test5() +void test5(void) { int rc; int count = 0; @@ -179,7 +179,7 @@ int cb6(void *arg, int line, const char *section, const char *key, return -1; } -void test6() +void test6(void) { int rc; int count = 0; @@ -217,7 +217,7 @@ int cb7(void *arg, int line, const char *section, const char *key, return 0; } -void test7() +void test7(void) { int rc; int count = 0; @@ -251,7 +251,7 @@ int cb8(void *arg, int line, const char *section, const char *key, return 0; } -void test8() +void test8(void) { int rc; int count = 0; @@ -357,7 +357,7 @@ int cb9(void *arg, int line, const char *section, const char *key, return 0; } -void test9() +void test9(void) { int rc; int count = 0; @@ -371,7 +371,7 @@ void test9() assert(rc == 0); } -void test10() +void test10(void) { int rc; int count = 0; @@ -397,7 +397,7 @@ int cb11(void *arg, int line, const char *section, const char *key, return 0; } -void test11() +void test11(void) { int rc; int count = 0; @@ -427,7 +427,7 @@ int cb12(void *arg, int line, const char *section, const char *key, return 0; } -void test12() +void test12(void) { int rc; int count = 0; @@ -463,7 +463,7 @@ int cb13(void *arg, int line, const char *section, const char *key, return 0; } -void test13() +void test13(void) { int rc; int count = 0; @@ -491,7 +491,7 @@ int cb14(void *arg, int line, const char *section, const char *key, return -1; } -void test14() +void test14(void) { int rc; int count = 0; @@ -517,7 +517,7 @@ int cb15(void *arg, int line, const char *section, const char *key, return -1; } -void test15() +void test15(void) { int rc; int count = 0; @@ -550,7 +550,7 @@ int cb16(void *arg, int line, const char *section, const char *key, return 0; } -void test16() +void test16(void) { int rc; @@ -636,7 +636,7 @@ int cb_fail(void *arg, int line, const char *section, const char *key, return 0; } -void test_fail() +void test_fail(void) { int rc; FILE *fp; @@ -656,12 +656,12 @@ void test_fail() fail_ferror = false; } #else -void test_fail() +void test_fail(void) { } #endif -int main() +int main(void) { example(); test1(); diff --git a/linked-list/README.md b/linked-list/README.md index a609e31..a0ee24c 100644 --- a/linked-list/README.md +++ b/linked-list/README.md @@ -16,7 +16,7 @@ #include -int main() +int main(void) { struct user { diff --git a/linked-list/list_example.c b/linked-list/list_example.c index 3db9c40..d0a4788 100644 --- a/linked-list/list_example.c +++ b/linked-list/list_example.c @@ -2,7 +2,7 @@ #include -int main() +int main(void) { struct user { char *name; diff --git a/linked-list/list_test.c b/linked-list/list_test.c index 8cbd65d..5a05f8b 100644 --- a/linked-list/list_test.c +++ b/linked-list/list_test.c @@ -174,7 +174,7 @@ static void test1(void) } } -int main() +int main(void) { test1(); diff --git a/logger/log_example.c b/logger/log_example.c index e8263b6..788865c 100644 --- a/logger/log_example.c +++ b/logger/log_example.c @@ -14,7 +14,7 @@ int log_callback(void *arg, enum sc_log_level level, const char *fmt, return 0; } -int main() +int main(void) { const char *my_app_name = "my app"; diff --git a/logger/log_test.c b/logger/log_test.c index 8b9fdb5..f01fe8b 100644 --- a/logger/log_test.c +++ b/logger/log_test.c @@ -363,7 +363,7 @@ void example(void) sc_log_term(); // Call once on shutdown. } -int main() +int main(void) { sc_log_set_thread_name("My thread"); diff --git a/map/README.md b/map/README.md index 9019ed4..6180290 100644 --- a/map/README.md +++ b/map/README.md @@ -59,7 +59,7 @@ void example_str(void) sc_map_term_str(&map); } -void example_int_to_str() +void example_int_to_str(void) { uint32_t key; const char *value; @@ -98,7 +98,7 @@ void example_int_to_str() sc_map_term_64s(&map); } -int main() +int main(void) { example_str(); example_int_to_str(); diff --git a/map/map_example.c b/map/map_example.c index 36a22de..aaaecda 100644 --- a/map/map_example.c +++ b/map/map_example.c @@ -20,7 +20,7 @@ void example_str(void) sc_map_term_str(&map); } -void example_int_to_str() +void example_int_to_str(void) { uint32_t key; const char *value; @@ -59,7 +59,7 @@ void example_int_to_str() sc_map_term_64s(&map); } -int main() +int main(void) { example_str(); example_int_to_str(); diff --git a/map/map_test.c b/map/map_test.c index 03a324e..0e9490c 100644 --- a/map/map_test.c +++ b/map/map_test.c @@ -23,7 +23,7 @@ void example(void) sc_map_term_str(&map); } -void example_int_to_str() +void example_int_to_str(void) { uint32_t key; const char *value; @@ -81,7 +81,7 @@ static char *str_random(size_t size) return dest; } -void test_32() +void test_32(void) { struct sc_map_32 map; @@ -158,7 +158,7 @@ void test_32() sc_map_term_32(&map); } -void test_64() +void test_64(void) { struct sc_map_64 map; @@ -234,7 +234,7 @@ void test_64() sc_map_term_64(&map); } -void test_64v() +void test_64v(void) { struct sc_map_64v map; @@ -310,7 +310,7 @@ void test_64v() sc_map_term_64v(&map); } -void test_64s() +void test_64s(void) { struct sc_map_64s map; @@ -385,7 +385,7 @@ void test_64s() sc_map_term_64s(&map); } -void test_str() +void test_str(void) { const char *arr = "abcdefghijklmnoprstuvyzabcdefghijklmnoprstuvyzabcdef" "ghijklmnoprstuvyz"; @@ -490,7 +490,7 @@ void test_str() sc_map_term_str(&map); } -void test_sv() +void test_sv(void) { const char *arr = "abcdefghijklmnoprstuvyzabcdefghijklmnoprstuvyzabcdef" "ghijklmnoprstuvyz"; @@ -593,7 +593,7 @@ void test_sv() sc_map_term_sv(&map); } -void test_s64() +void test_s64(void) { const char *arr = "abcdefghijklmnoprstuvyzabcdefghijklmnoprstuvyzabcdef" "ghijklmnoprstuvyz"; @@ -701,7 +701,7 @@ void test_s64() sc_map_term_s64(&map); } -void test0() +void test0(void) { uint64_t val; struct sc_map_64 map; @@ -749,7 +749,7 @@ void test0() sc_map_term_64(&map); } -void test1() +void test1(void) { struct sc_map_str map; char *keys[128]; @@ -901,7 +901,7 @@ void test1() } } -void test2() +void test2(void) { struct sc_map_32 map; uint32_t keys[128]; @@ -983,7 +983,7 @@ retry: sc_map_term_32(&map); } -void test3() +void test3(void) { struct sc_map_64 map; uint64_t keys[128]; @@ -1065,7 +1065,7 @@ retry: sc_map_term_64(&map); } -void test4() +void test4(void) { const char *c; struct sc_map_64s map64s; @@ -1184,7 +1184,7 @@ void test4() } } -static void test5() +static void test5(void) { int t = 0; uint64_t key, value; @@ -1219,7 +1219,7 @@ static void test5() sc_map_term_64(&map); } -static void test6() +static void test6(void) { const int count = 120000; uint32_t val; @@ -1260,7 +1260,7 @@ static void test6() free(values); } -static void test_loop_foreach() +static void test_loop_foreach(void) { struct sc_map_32 map; @@ -1306,7 +1306,7 @@ static void test_loop_foreach() sc_map_term_32(&map); } -static void test_loop_foreach_key() +static void test_loop_foreach_key(void) { struct sc_map_32 map; @@ -1350,7 +1350,7 @@ static void test_loop_foreach_key() sc_map_term_32(&map); } -static void test_loop_foreach_value() +static void test_loop_foreach_value(void) { struct sc_map_32 map; @@ -1394,7 +1394,7 @@ static void test_loop_foreach_value() sc_map_term_32(&map); } -void test_loop_generic() +void test_loop_generic(void) { struct sc_map_64 map; @@ -1494,7 +1494,7 @@ void *__wrap_calloc(size_t n, size_t size) return __real_calloc(n, size); } -void fail_test_32() +void fail_test_32(void) { struct sc_map_32 map; @@ -1521,7 +1521,7 @@ void fail_test_32() sc_map_term_32(&map); } -void fail_test_64() +void fail_test_64(void) { struct sc_map_64 map; @@ -1548,7 +1548,7 @@ void fail_test_64() sc_map_term_64(&map); } -void fail_test_64v() +void fail_test_64v(void) { struct sc_map_64v map; @@ -1575,7 +1575,7 @@ void fail_test_64v() sc_map_term_64v(&map); } -void fail_test_64s() +void fail_test_64s(void) { struct sc_map_64s map; @@ -1602,7 +1602,7 @@ void fail_test_64s() sc_map_term_64s(&map); } -void fail_test_str() +void fail_test_str(void) { struct sc_map_str map; const char *v; @@ -1642,7 +1642,7 @@ void fail_test_str() sc_map_term_str(&map); } -void fail_test_sv() +void fail_test_sv(void) { struct sc_map_sv map; const char *v; @@ -1681,7 +1681,7 @@ void fail_test_sv() sc_map_term_sv(&map); } -void fail_test_s64() +void fail_test_s64(void) { struct sc_map_s64 map; const char *v; @@ -1744,7 +1744,7 @@ void fail_test_s64(void) } #endif -int main() +int main(void) { example(); example_int_to_str(); diff --git a/memory-map/mmap_example.c b/memory-map/mmap_example.c index 591d793..6f69005 100644 --- a/memory-map/mmap_example.c +++ b/memory-map/mmap_example.c @@ -4,7 +4,7 @@ #include #include -int main() +int main(void) { int rc; struct sc_mmap mmap; diff --git a/memory-map/mmap_test.c b/memory-map/mmap_test.c index c5bd3d0..4f5e75e 100644 --- a/memory-map/mmap_test.c +++ b/memory-map/mmap_test.c @@ -8,7 +8,7 @@ #include #include -void test1() +void test1(void) { int rc; unsigned char *p; @@ -210,7 +210,7 @@ int __wrap_posix_fallocate64(int fd, off_t offset, off_t len) return __real_posix_fallocate64(fd, offset, len); } -void fail_test() +void fail_test(void) { int rc; struct sc_mmap mmap; @@ -302,7 +302,7 @@ void fail_test() } #endif -int main() +int main(void) { test1(); fail_test(); diff --git a/memory-map/sc_mmap.c b/memory-map/sc_mmap.c index a7a722e..484b483 100644 --- a/memory-map/sc_mmap.c +++ b/memory-map/sc_mmap.c @@ -258,7 +258,7 @@ int sc_mmap_init(struct sc_mmap *m, const char *name, int file_flags, int prot, } #else do { - rc = posix_fallocate(fd, offset, len); + rc = posix_fallocate(fd, (off_t) offset, (off_t) len); } while (rc == EINTR); if (rc != 0) { @@ -268,7 +268,7 @@ int sc_mmap_init(struct sc_mmap *m, const char *name, int file_flags, int prot, #endif } - p = mmap(NULL, len, prot, map_flags, fd, offset); + p = mmap(NULL, len, prot, map_flags, fd, (off_t) offset); if (p == MAP_FAILED) { goto cleanup_fd; } diff --git a/mutex/mutex_example.c b/mutex/mutex_example.c index 2853f1a..67e2b32 100644 --- a/mutex/mutex_example.c +++ b/mutex/mutex_example.c @@ -1,6 +1,6 @@ #include "sc_mutex.h" -int main() +int main(void) { struct sc_mutex mutex; diff --git a/mutex/mutex_test.c b/mutex/mutex_test.c index 90ee87a..6ae705b 100644 --- a/mutex/mutex_test.c +++ b/mutex/mutex_test.c @@ -72,7 +72,7 @@ int __wrap_pthread_mutex_init(pthread_mutex_t *__mutex, #endif -int main() +int main(void) { struct sc_mutex mutex; #ifdef SC_HAVE_WRAP diff --git a/option/README.md b/option/README.md index 1355de0..0f537fc 100644 --- a/option/README.md +++ b/option/README.md @@ -43,5 +43,6 @@ int main(int argc, char *argv[]) return 0; -}``` +} +``` diff --git a/option/option_test.c b/option/option_test.c index 7d2064f..cf0f6c2 100644 --- a/option/option_test.c +++ b/option/option_test.c @@ -9,7 +9,7 @@ static struct sc_option_item options[] = {{.letter = 's', .name = NULL}, {.letter = 'k', .name = "key"}, {.letter = 'h', .name = "help"}}; -void test1() +void test1(void) { char *value; int argc = 5; @@ -43,7 +43,7 @@ void test1() } } -void test2() +void test2(void) { char *value; int argc = 2; @@ -66,7 +66,7 @@ void test2() } } -void test3() +void test3(void) { char *value; int argc = 2; @@ -90,7 +90,7 @@ void test3() } } -void test4() +void test4(void) { char *value; @@ -118,7 +118,7 @@ static struct sc_option_item options2[] = {{.letter = 's', .name = "sadsa"}, {.letter = 'm', .name = "sad"}, {.letter = 'k', .name = "key3"}, {.letter = 'h', .name = "dsadsa"}}; -void test5() +void test5(void) { char *value; @@ -142,7 +142,7 @@ void test5() } } -void test6() +void test6(void) { char *value; int argc = 2; @@ -165,7 +165,7 @@ void test6() } } -void test7() +void test7(void) { char *value; int argc = 2; @@ -188,7 +188,7 @@ void test7() } } -void test8() +void test8(void) { char *value; int argc = 2; @@ -211,7 +211,7 @@ void test8() } } -int main() +int main(void) { test1(); test2(); diff --git a/perf/perf_example.c b/perf/perf_example.c index 6a662b1..baadd4e 100644 --- a/perf/perf_example.c +++ b/perf/perf_example.c @@ -2,7 +2,7 @@ #include -int main() +int main(void) { size_t total = 0; diff --git a/perf/sc_perf.c b/perf/sc_perf.c index 29ba375..14a8320 100644 --- a/perf/sc_perf.c +++ b/perf/sc_perf.c @@ -94,8 +94,8 @@ static void sc_perf_set(struct sc_perf_item *items, size_t size) .exclude_kernel = false, .exclude_hv = false}; - fd = syscall(__NR_perf_event_open, &p, 0, -1, -1, - PERF_FLAG_FD_CLOEXEC); + fd = (int) syscall(__NR_perf_event_open, &p, 0, -1, -1, + PERF_FLAG_FD_CLOEXEC); if (fd == -1) { fprintf(stderr, "Failed to set counter : %s , probably your " @@ -129,7 +129,7 @@ static void sc_read(struct sc_perf_item *items, size_t size) items[i].active = n; } - items[i].value += fmt.value * n; + items[i].value += (double) fmt.value * n; } } diff --git a/perf/sc_perf.h b/perf/sc_perf.h index 98bde5a..75eb4f8 100644 --- a/perf/sc_perf.h +++ b/perf/sc_perf.h @@ -116,8 +116,8 @@ static const struct sc_perf_event sc_perf_hw[] = { // clang-format on -void sc_perf_start(); -void sc_perf_pause(); -void sc_perf_end(); +void sc_perf_start(void); +void sc_perf_pause(void); +void sc_perf_end(void); #endif diff --git a/queue/queue_test.c b/queue/queue_test.c index e305089..ab2b74e 100644 --- a/queue/queue_test.c +++ b/queue/queue_test.c @@ -122,7 +122,7 @@ void example(void) sc_queue_term(&queue); } -void test0() +void test0(void) { uint32_t val; struct sc_queue_32 q; @@ -257,7 +257,7 @@ void test1(void) sc_queue_term(&p); } -int main() +int main(void) { fail_test(); example(); diff --git a/sc/sc_example.c b/sc/sc_example.c index a46866d..31dbf45 100644 --- a/sc/sc_example.c +++ b/sc/sc_example.c @@ -1,4 +1,4 @@ -int main() +int main(void) { return 0; } diff --git a/sc/sc_test.c b/sc/sc_test.c index 0020a79..f510531 100644 --- a/sc/sc_test.c +++ b/sc/sc_test.c @@ -8,7 +8,7 @@ #include #include -void test1() +void test1(void) { int64_t x; char *t; @@ -127,7 +127,7 @@ void test1() assert(strcmp(t, "16.00 EB") == 0); } -void test_rand() +void test_rand(void) { unsigned char tmp[256] = {0, 1, 2, 3, 4, 5, 6, 6, 6, 6, 1, 5, 3, 5, 5, 6}; @@ -200,7 +200,7 @@ extern long long int __wrap_strtoll(const char *__restrict nptr, return __real_strtoll(nptr, endptr, base); } -void fail_test() +void fail_test(void) { char *t; int64_t val; @@ -239,11 +239,11 @@ void fail_test() } #else -void fail_test() +void fail_test(void) { } #endif -int main() +int main(void) { test1(); test_rand(); diff --git a/signal/README.md b/signal/README.md index cc3ef23..9406363 100644 --- a/signal/README.md +++ b/signal/README.md @@ -22,7 +22,7 @@ #include #include -int main() +int main(void) { char tmp[1]; int fds[2]; diff --git a/signal/sc_signal.c b/signal/sc_signal.c index cdd6b7a..6408dbd 100644 --- a/signal/sc_signal.c +++ b/signal/sc_signal.c @@ -472,7 +472,7 @@ static void sc_signal_on_fatal(int sig, siginfo_t *info, void *context) #endif } -int sc_signal_init() +int sc_signal_init(void) { bool rc = true; struct sigaction action; diff --git a/signal/sc_signal.h b/signal/sc_signal.h index b6ad854..dab691f 100644 --- a/signal/sc_signal.h +++ b/signal/sc_signal.h @@ -66,7 +66,7 @@ extern volatile sig_atomic_t sc_signal_will_shutdown; * Init signal handler, hooks for shutdown signals and some fatal signals. * @return '0' on success, '-1' on failure */ -int sc_signal_init(); +int sc_signal_init(void); /** * Signal safe logging diff --git a/signal/signal_example.c b/signal/signal_example.c index e56436b..b10ffd3 100644 --- a/signal/signal_example.c +++ b/signal/signal_example.c @@ -1,6 +1,6 @@ #include "sc_signal.h" -int main() +int main(void) { return 0; } diff --git a/signal/signal_test.c b/signal/signal_test.c index 6d6f1be..c5d7a79 100644 --- a/signal/signal_test.c +++ b/signal/signal_test.c @@ -3,7 +3,7 @@ #include #include -void test1() +void test1(void) { char tmp[128] = ""; @@ -41,7 +41,7 @@ void test1() sc_signal_log(1, tmp, sizeof(tmp), "%s", "test"); } -void test2() +void test2(void) { assert(sc_signal_init() == 0); } @@ -91,7 +91,7 @@ void test3x(int signal) } } -void test3() +void test3(void) { test3x(SIGSEGV); test3x(SIGABRT); @@ -129,14 +129,14 @@ void test4x(int signal) } } -void test4() +void test4(void) { test4x(SIGINT); test4x(SIGTERM); test4x(SIGUSR2); } -void test5() +void test5(void) { pid_t pid = fork(); if (pid == -1) { @@ -161,7 +161,7 @@ void test5() } } -void test6() +void test6(void) { pid_t pid = fork(); if (pid == -1) { @@ -185,7 +185,7 @@ void test6() } } -void test7() +void test7(void) { pid_t pid = fork(); if (pid == -1) { @@ -208,7 +208,7 @@ void test7() } } -void test8() +void test8(void) { pid_t pid = fork(); if (pid == -1) { @@ -232,7 +232,7 @@ void test8() } } -void test9() +void test9(void) { fail_signal = true; assert(sc_signal_init() != 0); @@ -240,30 +240,30 @@ void test9() } #else -void test3() +void test3(void) { } -void test4() +void test4(void) { } -void test5() +void test5(void) { } -void test6() +void test6(void) { } -void test7() +void test7(void) { } -void test8() +void test8(void) { } -void test9() +void test9(void) { } #endif -int main() +int main(void) { test1(); test2(); diff --git a/socket/sc_sock.c b/socket/sc_sock.c index 0f480af..77ac949 100644 --- a/socket/sc_sock.c +++ b/socket/sc_sock.c @@ -183,24 +183,24 @@ int sc_sock_notify_systemd(const char *msg) msghdr.msg_namelen = sizeof(struct sockaddr_un); } - rc = sendmsg(fd, &msghdr, MSG_NOSIGNAL); + rc = (int) sendmsg(fd, &msghdr, MSG_NOSIGNAL); close(fd); return rc < 0 ? -1 : 0; } -int sc_sock_startup() +int sc_sock_startup(void) { return 0; } -int sc_sock_cleanup() +int sc_sock_cleanup(void) { return 0; } -static int sc_sock_err() +static int sc_sock_err(void) { return errno; } @@ -1028,7 +1028,7 @@ retry: goto retry; } - return n; + return (int) n; } int sc_sock_pipe_read(struct sc_sock_pipe *p, void *data, unsigned int len) @@ -1042,7 +1042,7 @@ retry: goto retry; } - return n; + return (int) n; } #endif diff --git a/socket/sc_sock.h b/socket/sc_sock.h index 25f4854..9ff7771 100644 --- a/socket/sc_sock.h +++ b/socket/sc_sock.h @@ -92,13 +92,13 @@ struct sc_sock { * Call once when your application starts. * @return 0 on success, negative on failure. */ -int sc_sock_startup(); +int sc_sock_startup(void); /** * Call once before your application terminates * @return 0 on success, negative on failure. */ -int sc_sock_cleanup(); +int sc_sock_cleanup(void); /** * Initialize sock diff --git a/socket/sock_example.c b/socket/sock_example.c index fc047f7..3aab72f 100644 --- a/socket/sock_example.c +++ b/socket/sock_example.c @@ -1,5 +1,5 @@ -int main() +int main(void) { return 0; } diff --git a/socket/sock_test.c b/socket/sock_test.c index ec87cb4..adfd912 100644 --- a/socket/sock_test.c +++ b/socket/sock_test.c @@ -207,7 +207,7 @@ void *client_ip4(void *arg) return NULL; } -void test_ip4() +void test_ip4(void) { struct sc_thread thread1; struct sc_thread thread2; @@ -267,7 +267,7 @@ void *client_ip6(void *arg) return NULL; } -void test_ip6() +void test_ip6(void) { struct sc_thread thread1; struct sc_thread thread2; @@ -335,7 +335,7 @@ void *client_unix(void *arg) return NULL; } -void test_unix() +void test_unix(void) { struct sc_thread thread1; struct sc_thread thread2; @@ -350,7 +350,7 @@ void test_unix() assert(sc_thread_term(&thread2) == 0); } -void test1() +void test1(void) { int rc; char tmp[5]; @@ -835,7 +835,7 @@ int __wrap_getsockname(int fd, struct sockaddr *addr, socklen_t *len) return __real_getsockname(fd, addr, len); } -void poll_fail_test() +void poll_fail_test(void) { bool fail; int i; @@ -1027,7 +1027,7 @@ void poll_fail_test() assert(sc_sock_poll_term(&poll) == 0); } -void pipe_fail_test() +void pipe_fail_test(void) { struct sc_sock_pipe pipe; fail_pipe = true; @@ -1062,7 +1062,7 @@ void pipe_fail_test() fail_read_errno = 0; } -void sock_fail_test() +void sock_fail_test(void) { struct sc_sock sock; struct sc_sock sock2; @@ -1162,7 +1162,7 @@ void sock_fail_test() fail_socket = 0; } -void sock_fail_test2() +void sock_fail_test2(void) { int rc; struct sc_sock sock, client, in; @@ -1281,7 +1281,7 @@ void sock_fail_test2() assert(sc_sock_term(&client) == 0); } -void sock_fail_test3() +void sock_fail_test3(void) { struct sc_sock client; struct sc_sock_poll poll; @@ -1404,20 +1404,20 @@ void sock_fail_test3() } #else -void sock_fail_test() +void sock_fail_test(void) { } -void sock_fail_test2() +void sock_fail_test2(void) { } -void sock_fail_test3() +void sock_fail_test3(void) { } -void poll_fail_test() +void poll_fail_test(void) { } -void pipe_fail_test() +void pipe_fail_test(void) { } @@ -1426,7 +1426,8 @@ void pipe_fail_test() void *server(void *arg) { (void) arg; - int wr = 2, ev; + uint32_t ev; + int wr = 2; int rc, received = 0; struct sc_sock srv, in, *sock; struct sc_sock_poll p; @@ -1552,7 +1553,7 @@ void *client(void *arg) return NULL; } -void test_poll() +void test_poll(void) { struct sc_thread thread1; struct sc_thread thread2; @@ -1567,7 +1568,7 @@ void test_poll() assert(sc_thread_term(&thread2) == 0); } -void test_err() +void test_err(void) { struct sc_sock sock; char buf[128]; @@ -1606,7 +1607,7 @@ void test_err() assert(*sc_sock_poll_err(&p) != '\0'); } -int main() +int main(void) { #ifdef SC_HAVE_WRAP assert(sc_mutex_init(&mutex) == 0); diff --git a/string/str_example.c b/string/str_example.c index 3396434..e5c16eb 100644 --- a/string/str_example.c +++ b/string/str_example.c @@ -2,7 +2,7 @@ #include -int main() +int main(void) { char *s1; diff --git a/string/str_test.c b/string/str_test.c index 865270f..57c1976 100644 --- a/string/str_test.c +++ b/string/str_test.c @@ -60,7 +60,7 @@ int __wrap_vsnprintf(char *str, size_t size, const char *format, va_list ap) return fail_vnsprintf_value; } -void test1() +void test1(void) { char *m = sc_str_create(NULL); sc_str_destroy(&m); @@ -170,7 +170,7 @@ void test1() fail_vsnprintf = false; } -void test2() +void test2(void) { char buf[4000]; memset(buf, 'x', 4000); @@ -267,7 +267,7 @@ void test2() #endif -void test3() +void test3(void) { const char *tokens = "token;token;token;token"; char *save = NULL; @@ -350,7 +350,7 @@ void test3() sc_str_destroy(&str); } -void test4() +void test4(void) { char *save = NULL; const char *token; @@ -415,7 +415,7 @@ void test4() sc_str_destroy(&str); } -void test5() +void test5(void) { char *s1, *s2; @@ -519,7 +519,7 @@ void test5() sc_str_destroy(&s1); } -void test6() +void test6(void) { char *s1, *s2; char *save = NULL; @@ -588,7 +588,7 @@ void test6() sc_str_destroy(&s2); } -int main() +int main(void) { #ifdef SC_HAVE_WRAP diff --git a/thread/thread_example.c b/thread/thread_example.c index fd599b7..9f25dd7 100644 --- a/thread/thread_example.c +++ b/thread/thread_example.c @@ -8,7 +8,7 @@ void *fn(void *arg) return arg; } -int main() +int main(void) { struct sc_thread thread; diff --git a/thread/thread_test.c b/thread/thread_test.c index f18c8a6..be43ff0 100644 --- a/thread/thread_test.c +++ b/thread/thread_test.c @@ -11,7 +11,7 @@ void *fn(void *arg) return arg; } -void test1() +void test1(void) { int rc; void *ret; @@ -76,7 +76,7 @@ int __wrap_pthread_join(pthread_t th, void **thread_return) return rc; } -void fail_test() +void fail_test(void) { struct sc_thread thread; @@ -99,12 +99,12 @@ void fail_test() } #else -void fail_test() +void fail_test(void) { } #endif -int main() +int main(void) { test1(); fail_test(); diff --git a/time/sc_time.c b/time/sc_time.c index 7314539..03e00db 100644 --- a/time/sc_time.c +++ b/time/sc_time.c @@ -44,7 +44,7 @@ #include #endif -uint64_t sc_time_ms() +uint64_t sc_time_ms(void) { #if defined(_WIN32) || defined(_WIN64) FILETIME ft; @@ -63,11 +63,11 @@ uint64_t sc_time_ms() assert(rc == 0); (void) rc; - return ts.tv_sec * 1000 + (uint64_t) (ts.tv_nsec / 10e6); + return ts.tv_sec * 1000 + (uint64_t) (ts.tv_nsec / 1000000); #endif } -uint64_t sc_time_ns() +uint64_t sc_time_ns(void) { #if defined(_WIN32) || defined(_WIN64) FILETIME ft; @@ -90,7 +90,7 @@ uint64_t sc_time_ns() #endif } -uint64_t sc_time_mono_ms() +uint64_t sc_time_mono_ms(void) { #if defined(_WIN32) || defined(_WIN64) // System frequency does not change at run-time, cache it @@ -117,7 +117,7 @@ uint64_t sc_time_mono_ms() #endif } -uint64_t sc_time_mono_ns() +uint64_t sc_time_mono_ns(void) { #if defined(_WIN32) || defined(_WIN64) static int64_t frequency = 0; @@ -151,8 +151,8 @@ int sc_time_sleep(uint64_t millis) int rc; struct timespec t, rem; - rem.tv_sec = millis / 1000; - rem.tv_nsec = (millis % 1000) * 1000000; + rem.tv_sec = (time_t) millis / 1000; + rem.tv_nsec = (long) (millis % 1000) * 1000000; do { t = rem; diff --git a/time/sc_time.h b/time/sc_time.h index 2219863..ec17289 100644 --- a/time/sc_time.h +++ b/time/sc_time.h @@ -39,25 +39,25 @@ * Wall clock time. Gets CLOCK_REALTIME on Posix. * @return current timestamp in milliseconds. */ -uint64_t sc_time_ms(); +uint64_t sc_time_ms(void); /** * Wall clock time. Gets CLOCK_REALTIME on Posix. * @return current timestamp in nanoseconds. */ -uint64_t sc_time_ns(); +uint64_t sc_time_ns(void); /** * Monotonic timer. Gets CLOCK_MONOTONIC on Posix * @return current timestamp in milliseconds. */ -uint64_t sc_time_mono_ms(); +uint64_t sc_time_mono_ms(void); /** * Monotonic timer. Gets CLOCK_MONOTONIC on Posix * @return Current timestamp in nanoseconds. */ -uint64_t sc_time_mono_ns(); +uint64_t sc_time_mono_ns(void); /** * @param millis milliseconds to sleep. diff --git a/time/time_example.c b/time/time_example.c index 2a729d0..875c51e 100644 --- a/time/time_example.c +++ b/time/time_example.c @@ -2,7 +2,7 @@ #include -int main() +int main(void) { uint64_t t = sc_time_ms(); sc_time_sleep(1000); diff --git a/time/time_test.c b/time/time_test.c index a15c038..13d5be9 100644 --- a/time/time_test.c +++ b/time/time_test.c @@ -109,7 +109,7 @@ void test4(void) } #endif -int main() +int main(void) { test1(); test2(); diff --git a/timer/sc_timer.c b/timer/sc_timer.c index 19f36cf..f89d15f 100644 --- a/timer/sc_timer.c +++ b/timer/sc_timer.c @@ -192,7 +192,7 @@ uint64_t sc_timer_timeout(struct sc_timer *t, uint64_t timestamp, void *arg, callback(arg, timeout, item->type, item->data); // Recalculates position each time because there - // might be newly added timers in the callback + // might be newly added timers in the callback, // and it might require expansion of the list. base = t->wheel * head; } diff --git a/timer/timer_example.c b/timer/timer_example.c index 7c47360..11e592d 100644 --- a/timer/timer_example.c +++ b/timer/timer_example.c @@ -8,7 +8,7 @@ #include #include -uint64_t time_ms(); +uint64_t time_ms(void); void sleep_ms(uint64_t milliseconds); void callback(void *arg, uint64_t timeout, uint64_t type, void *data) @@ -24,7 +24,7 @@ void callback(void *arg, uint64_t timeout, uint64_t type, void *data) sc_timer_add(timer, 1000, 1, "timer1"); } -int main() +int main(void) { uint64_t next_timeout; struct sc_timer timer; @@ -47,7 +47,7 @@ int main() #include #endif -uint64_t time_ms() +uint64_t time_ms(void) { #if defined(_WIN32) || defined(_WIN64) // System frequency does not change at run-time, cache it diff --git a/timer/timer_test.c b/timer/timer_test.c index 65845b0..66e498a 100644 --- a/timer/timer_test.c +++ b/timer/timer_test.c @@ -17,7 +17,7 @@ #include #endif -uint64_t time_ms() +uint64_t time_ms(void) { #if defined(_WIN32) || defined(_WIN64) // System frequency does not change at run-time, cache it @@ -68,14 +68,11 @@ void callback(void *arg, uint64_t timeout, uint64_t type, void *data) (void) timeout; (void) type; - static int idx = 0; count--; uint64_t id = (uintptr_t) data; assert(ids[id] != SC_TIMER_INVALID); ids[id] = SC_TIMER_INVALID; assert((int) (uintptr_t) arg == 333); - - idx++; } void test1(void) @@ -326,7 +323,7 @@ void fail_test(void) } #endif -int main() +int main(void) { fail_test(); test1(); diff --git a/uri/uri_example.c b/uri/uri_example.c index c8a791d..bb48b7c 100644 --- a/uri/uri_example.c +++ b/uri/uri_example.c @@ -2,7 +2,7 @@ #include -int main() +int main(void) { struct sc_uri *uri; uri = sc_uri_create("http://user:pass@any.com:8042/over/" diff --git a/uri/uri_test.c b/uri/uri_test.c index 3c95e43..a889977 100644 --- a/uri/uri_test.c +++ b/uri/uri_test.c @@ -317,7 +317,7 @@ int __wrap_sprintf(char *str, const char *format, ...) return fail_sprintf; } -void fail_test() +void fail_test(void) { struct sc_uri *uri; fail_malloc = true; @@ -362,7 +362,7 @@ void fail_test() } #endif -int main() +int main(void) { test1(); test2();