Commit | Line | Data |
---|---|---|
70bd0a12 JD |
1 | #ifndef _BABELTRACE_INTERNAL_H |
2 | #define _BABELTRACE_INTERNAL_H | |
3 | ||
eb31c5e6 MD |
4 | /* |
5 | * babeltrace/babeltrace-internal.h | |
6 | * | |
7 | * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 | * of this software and associated documentation files (the "Software"), to deal | |
11 | * in the Software without restriction, including without limitation the rights | |
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 | * copies of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
c462e188 MD |
18 | * |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
25 | * SOFTWARE. | |
eb31c5e6 | 26 | */ |
70bd0a12 JD |
27 | #include <stdio.h> |
28 | #include <glib.h> | |
11ac6674 | 29 | #include <stdint.h> |
f3e4505b JG |
30 | #include <stdlib.h> |
31 | #include <errno.h> | |
3d9990ac | 32 | #include <babeltrace/compat/string-internal.h> |
c55a9f58 | 33 | #include <babeltrace/types.h> |
fd3c708f MD |
34 | |
35 | #define PERROR_BUFLEN 200 | |
70bd0a12 | 36 | |
196409fe EB |
37 | #ifndef likely |
38 | # ifdef __GNUC__ | |
39 | # define likely(x) __builtin_expect(!!(x), 1) | |
40 | # else | |
41 | # define likely(x) (!!(x)) | |
42 | # endif | |
43 | #endif | |
44 | ||
45 | #ifndef unlikely | |
46 | # ifdef __GNUC__ | |
47 | # define unlikely(x) __builtin_expect(!!(x), 0) | |
48 | # else | |
49 | # define unlikely(x) (!!(x)) | |
50 | # endif | |
51 | #endif | |
90bf3cef | 52 | |
40af9f9f JG |
53 | #ifndef min |
54 | #define min(a, b) (((a) < (b)) ? (a) : (b)) | |
55 | #endif | |
56 | ||
57 | #ifndef max | |
58 | #define max(a, b) (((a) > (b)) ? (a) : (b)) | |
59 | #endif | |
60 | ||
f3e4505b JG |
61 | #ifndef max_t |
62 | #define max_t(type, a, b) \ | |
63 | ((type) (a) > (type) (b) ? (type) (a) : (type) (b)) | |
64 | #endif | |
65 | ||
66 | /* | |
67 | * Memory allocation zeroed | |
68 | */ | |
69 | #define zmalloc(x) calloc(1, x) | |
70 | ||
5d6c80a5 JD |
71 | /* |
72 | * BT_HIDDEN: set the hidden attribute for internal functions | |
675860f4 MJ |
73 | * On Windows, symbols are local unless explicitly exported, |
74 | * see https://gcc.gnu.org/wiki/Visibility | |
5d6c80a5 | 75 | */ |
675860f4 MJ |
76 | #if defined(_WIN32) || defined(__CYGWIN__) |
77 | #define BT_HIDDEN | |
78 | #else | |
5d6c80a5 | 79 | #define BT_HIDDEN __attribute__((visibility("hidden"))) |
675860f4 | 80 | #endif |
5d6c80a5 | 81 | |
20ccd9e1 | 82 | #ifndef __STRINGIFY |
6fbd4105 | 83 | #define __STRINGIFY(x) #x |
20ccd9e1 MJ |
84 | #endif |
85 | ||
6fbd4105 PP |
86 | #define TOSTRING(x) __STRINGIFY(x) |
87 | ||
a7252d9c PP |
88 | #define BT_UNUSED __attribute__((unused)) |
89 | ||
70bd0a12 | 90 | #endif |