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