diff options
author | iphydf <iphydf@users.noreply.github.com> | 2019-01-12 13:12:39 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2019-01-12 13:12:39 +0000 |
commit | 91ff39599d97d610321970161ba6410f3bdd9b51 (patch) | |
tree | 30ada73995b857c9bde65a577427db4199426692 /toxcore/util.h | |
parent | 3dd31b1fd06a39a460e259ad525449b7f64e4a70 (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.h | 15 |
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 */ |
47 | int create_recursive_mutex(pthread_mutex_t *mutex); | 47 | int 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). | ||
53 | int16_t max_s16(int16_t a, int16_t b); | ||
49 | int32_t max_s32(int32_t a, int32_t b); | 54 | int32_t max_s32(int32_t a, int32_t b); |
55 | int64_t max_s64(int64_t a, int64_t b); | ||
56 | |||
57 | int16_t min_s16(int16_t a, int16_t b); | ||
50 | int32_t min_s32(int32_t a, int32_t b); | 58 | int32_t min_s32(int32_t a, int32_t b); |
59 | int64_t min_s64(int64_t a, int64_t b); | ||
60 | |||
61 | uint16_t max_u16(uint16_t a, uint16_t b); | ||
62 | uint32_t max_u32(uint32_t a, uint32_t b); | ||
63 | uint64_t max_u64(uint64_t a, uint64_t b); | ||
64 | |||
65 | uint16_t min_u16(uint16_t a, uint16_t b); | ||
51 | uint32_t min_u32(uint32_t a, uint32_t b); | 66 | uint32_t min_u32(uint32_t a, uint32_t b); |
52 | uint64_t min_u64(uint64_t a, uint64_t b); | 67 | uint64_t min_u64(uint64_t a, uint64_t b); |
53 | 68 | ||