summaryrefslogtreecommitdiff
path: root/toxcore/util.h
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2019-01-12 13:12:39 +0000
committeriphydf <iphydf@users.noreply.github.com>2019-01-12 13:12:39 +0000
commit91ff39599d97d610321970161ba6410f3bdd9b51 (patch)
tree30ada73995b857c9bde65a577427db4199426692 /toxcore/util.h
parent3dd31b1fd06a39a460e259ad525449b7f64e4a70 (diff)
Implement all min/max functions for (un)signed int types.
Also, use them in the `onion_client` module.
Diffstat (limited to 'toxcore/util.h')
-rw-r--r--toxcore/util.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/toxcore/util.h b/toxcore/util.h
index 85586724..79f5deb5 100644
--- a/toxcore/util.h
+++ b/toxcore/util.h
@@ -46,8 +46,23 @@ void net_to_host(uint8_t *num, uint16_t numbytes);
46/* Returns -1 if failed or 0 if success */ 46/* Returns -1 if failed or 0 if success */
47int create_recursive_mutex(pthread_mutex_t *mutex); 47int create_recursive_mutex(pthread_mutex_t *mutex);
48 48
49// Safe min/max functions with specific types. This forces the conversion to the
50// desired type before the comparison expression, giving the choice of
51// conversion to the caller. Use these instead of inline comparisons or MIN/MAX
52// macros (effectively inline comparisons).
53int16_t max_s16(int16_t a, int16_t b);
49int32_t max_s32(int32_t a, int32_t b); 54int32_t max_s32(int32_t a, int32_t b);
55int64_t max_s64(int64_t a, int64_t b);
56
57int16_t min_s16(int16_t a, int16_t b);
50int32_t min_s32(int32_t a, int32_t b); 58int32_t min_s32(int32_t a, int32_t b);
59int64_t min_s64(int64_t a, int64_t b);
60
61uint16_t max_u16(uint16_t a, uint16_t b);
62uint32_t max_u32(uint32_t a, uint32_t b);
63uint64_t max_u64(uint64_t a, uint64_t b);
64
65uint16_t min_u16(uint16_t a, uint16_t b);
51uint32_t min_u32(uint32_t a, uint32_t b); 66uint32_t min_u32(uint32_t a, uint32_t b);
52uint64_t min_u64(uint64_t a, uint64_t b); 67uint64_t min_u64(uint64_t a, uint64_t b);
53 68