Enforce const-correctness in UNIX socket wrappers
[lttng-tools.git] / src / common / macros.h
CommitLineData
990570ed
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
d14d33bf
AM
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
990570ed
DG
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d14d33bf 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
990570ed
DG
12 * more details.
13 *
d14d33bf
AM
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
990570ed
DG
17 */
18
19#ifndef _MACROS_H
20#define _MACROS_H
21
22#include <stdlib.h>
23
24/*
25 * Takes a pointer x and transform it so we can use it to access members
26 * without a function call. Here an example:
27 *
28 * #define GET_SIZE(x) LTTNG_REF(x)->size
29 *
30 * struct { int size; } s;
31 *
32 * printf("size : %d\n", GET_SIZE(&s));
33 *
34 * For this example we can't use something like this for compatibility purpose
35 * since this will fail:
36 *
37 * #define GET_SIZE(x) x->size;
38 *
39 * This is mostly use for the compatibility layer of lttng-tools. See
40 * poll/epoll for a good example. Since x can be on the stack or allocated
41 * memory using malloc(), we must use generic accessors for compat in order to
42 * *not* use a function to access members and not the variable name.
43 */
44#define LTTNG_REF(x) ((typeof(*x) *)(x))
45
46/*
47 * Memory allocation zeroed
48 */
4616a46c
MD
49static inline
50void *zmalloc(size_t len)
51{
52 return calloc(1, len);
53}
990570ed
DG
54
55#ifndef ARRAY_SIZE
56#define ARRAY_SIZE(array) (sizeof(array) / (sizeof((array)[0])))
57#endif
58
cf3f19ae
SM
59#ifndef max
60#define max(a, b) ((a) > (b) ? (a) : (b))
61#endif
62
331744e3
JD
63#ifndef max_t
64#define max_t(type, a, b) ((type) max(a, b))
65#endif
66
cf3f19ae
SM
67#ifndef min
68#define min(a, b) ((a) < (b) ? (a) : (b))
69#endif
70
54c90d10
DG
71#ifndef LTTNG_PACKED
72#define LTTNG_PACKED __attribute__((__packed__))
73#endif
74
99c815c1
DG
75#ifndef LTTNG_HIDDEN
76#define LTTNG_HIDDEN __attribute__((visibility("hidden")))
77#endif
78
990570ed 79#endif /* _MACROS_H */
This page took 0.03977 seconds and 4 git commands to generate.