d58b9860c8b5c65a71a811a7799c1da495a1aaa9
[babeltrace.git] / include / babeltrace / babeltrace-internal.h
1 #ifndef _BABELTRACE_INTERNAL_H
2 #define _BABELTRACE_INTERNAL_H
3
4 /*
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.
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.
24 */
25 #include <stdio.h>
26 #include <glib.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <babeltrace/compat/string-internal.h>
31 #include <babeltrace/types.h>
32
33 #define PERROR_BUFLEN 200
34
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
50
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
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
69 /*
70 * BT_HIDDEN: set the hidden attribute for internal functions
71 * On Windows, symbols are local unless explicitly exported,
72 * see https://gcc.gnu.org/wiki/Visibility
73 */
74 #if defined(_WIN32) || defined(__CYGWIN__)
75 #define BT_HIDDEN
76 #else
77 #define BT_HIDDEN __attribute__((visibility("hidden")))
78 #endif
79
80 #ifndef __STRINGIFY
81 #define __STRINGIFY(x) #x
82 #endif
83
84 #define TOSTRING(x) __STRINGIFY(x)
85
86 #define BT_UNUSED __attribute__((unused))
87
88 #endif
This page took 0.031381 seconds and 4 git commands to generate.