src/common/{common,safe}.h: wrap code in C++ guards
[babeltrace.git] / src / common / safe.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7 #include <stdbool.h>
8 #include <stdint.h>
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 static inline
15 bool bt_safe_to_mul_int64(int64_t a, int64_t b)
16 {
17 if (a == 0 || b == 0) {
18 return true;
19 }
20
21 return a < INT64_MAX / b;
22 }
23
24 static inline
25 bool bt_safe_to_mul_uint64(uint64_t a, uint64_t b)
26 {
27 if (a == 0 || b == 0) {
28 return true;
29 }
30
31 return a < UINT64_MAX / b;
32 }
33
34 static inline
35 bool bt_safe_to_add_int64(int64_t a, int64_t b)
36 {
37 return a <= INT64_MAX - b;
38 }
39
40 static inline
41 bool bt_safe_to_add_uint64(uint64_t a, uint64_t b)
42 {
43 return a <= UINT64_MAX - b;
44 }
45
46 #ifdef __cplusplus
47 }
48 #endif
This page took 0.029636 seconds and 4 git commands to generate.