summaryrefslogtreecommitdiff
path: root/toxcore/util.h
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-07-12 17:22:20 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-12 20:21:42 +0000
commitbeeb9b4335d9ca6f947a52528453753a51f194f3 (patch)
tree242cad42e2e90ebf5ed04283fd79f42f4e3afa60 /toxcore/util.h
parentcbda01021c561bd061cb03a1c1bab58199ac2307 (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.h')
-rw-r--r--toxcore/util.h6
1 files changed, 2 insertions, 4 deletions
diff --git a/toxcore/util.h b/toxcore/util.h
index 4c5023cf..76951fff 100644
--- a/toxcore/util.h
+++ b/toxcore/util.h
@@ -36,20 +36,18 @@
36extern "C" { 36extern "C" {
37#endif 37#endif
38 38
39#define MIN(a,b) (((a)<(b))?(a):(b))
40#define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; }
41
42/* id functions */ 39/* id functions */
43bool id_equal(const uint8_t *dest, const uint8_t *src); 40bool id_equal(const uint8_t *dest, const uint8_t *src);
44uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_ID_SIZE */ 41uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_ID_SIZE */
45 42
46void host_to_net(uint8_t *num, uint16_t numbytes); 43void host_to_net(uint8_t *num, uint16_t numbytes);
47#define net_to_host(x, y) host_to_net(x, y) 44void net_to_host(uint8_t *num, uint16_t numbytes);
48 45
49/* Returns -1 if failed or 0 if success */ 46/* Returns -1 if failed or 0 if success */
50int create_recursive_mutex(pthread_mutex_t *mutex); 47int create_recursive_mutex(pthread_mutex_t *mutex);
51 48
52int32_t max_s32(int32_t a, int32_t b); 49int32_t max_s32(int32_t a, int32_t b);
50uint32_t min_u32(uint32_t a, uint32_t b);
53uint64_t min_u64(uint64_t a, uint64_t b); 51uint64_t min_u64(uint64_t a, uint64_t b);
54 52
55#ifdef __cplusplus 53#ifdef __cplusplus