diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-07-12 17:22:20 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-07-12 20:21:42 +0000 |
commit | beeb9b4335d9ca6f947a52528453753a51f194f3 (patch) | |
tree | 242cad42e2e90ebf5ed04283fd79f42f4e3afa60 /toxcore/util.c | |
parent | cbda01021c561bd061cb03a1c1bab58199ac2307 (diff) |
Style fixes in TCP code; remove MIN and PAIR from util.h.
* Moved PAIR to toxav, where it's used (but really this should die).
* Replace most MIN calls with typed `min_*` calls. Didn't replace the
ones where the desired semantics are unclear. Moved the MIN macro to
the one place where it's still used.
* Avoid assignments in `while` loops. Instead, factored out the loop body
into a separate `bool`-returning function.
* Use named types for callbacks (`_cb` types).
* Avoid assignments in `if` conditions.
* Removed `MAKE_REALLOC` and expanded its two calls. We can't have
templates in C, and this fake templating is ugly and hard to analyse
and debug (it expands on a single line).
* Moved epoll system include to the .c file, out of the .h file.
* Avoid assignments in expressions (`a = b = c;`).
* Avoid multiple declarators per struct member declaration.
* Fix naming inconsistencies.
* Replace `net_to_host` macro with function.
Diffstat (limited to 'toxcore/util.c')
-rw-r--r-- | toxcore/util.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/toxcore/util.c b/toxcore/util.c index 5ab092ce..f349e8fe 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -66,6 +66,11 @@ void host_to_net(uint8_t *num, uint16_t numbytes) | |||
66 | #endif | 66 | #endif |
67 | } | 67 | } |
68 | 68 | ||
69 | void net_to_host(uint8_t *num, uint16_t numbytes) | ||
70 | { | ||
71 | host_to_net(num, numbytes); | ||
72 | } | ||
73 | |||
69 | int create_recursive_mutex(pthread_mutex_t *mutex) | 74 | int create_recursive_mutex(pthread_mutex_t *mutex) |
70 | { | 75 | { |
71 | pthread_mutexattr_t attr; | 76 | pthread_mutexattr_t attr; |
@@ -95,6 +100,11 @@ int32_t max_s32(int32_t a, int32_t b) | |||
95 | return a > b ? a : b; | 100 | return a > b ? a : b; |
96 | } | 101 | } |
97 | 102 | ||
103 | uint32_t min_u32(uint32_t a, uint32_t b) | ||
104 | { | ||
105 | return a < b ? a : b; | ||
106 | } | ||
107 | |||
98 | uint64_t min_u64(uint64_t a, uint64_t b) | 108 | uint64_t min_u64(uint64_t a, uint64_t b) |
99 | { | 109 | { |
100 | return a < b ? a : b; | 110 | return a < b ? a : b; |