License text standardization, add missing licenses
[lttng-ust.git] / include / lttng / bug.h
CommitLineData
44d13f19
MD
1#ifndef _LTTNG_BUG_H
2#define _LTTNG_BUG_H
3
4/*
3f12fcef 5 * lttng/bug.h
44d13f19
MD
6 *
7 * (C) Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
e92f3e28
MD
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:
a60d70e6 15 *
e92f3e28
MD
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
44d13f19
MD
18 */
19
3f12fcef
MD
20#include <urcu/compiler.h>
21#include <stdio.h>
22#include <stdlib.h>
23
24#define LTTNG_BUG_ON(condition) \
25 do { \
26 if (caa_unlikely(condition)) { \
27 fprintf(stderr, \
28 "LTTng BUG in file %s, line %d.\n", \
29 __FILE__, __LINE__); \
30 exit(EXIT_FAILURE); \
31 } \
32 } while (0)
33
34#define LTTNG_BUILD_BUG_ON(condition) \
a6352fd4
MD
35 ((void) sizeof(char[-!!(condition)]))
36
44d13f19 37/**
3f12fcef 38 * LTTNG_BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime
44d13f19
MD
39 * @condition: the condition which should be false.
40 *
41 * If the condition is a constant and true, the compiler will generate a build
42 * error. If the condition is not constant, a BUG will be triggered at runtime
43 * if the condition is ever true. If the condition is constant and false, no
44 * code is emitted.
45 */
3f12fcef 46#define LTTNG_BUILD_RUNTIME_BUG_ON(condition) \
44d13f19
MD
47 do { \
48 if (__builtin_constant_p(condition)) \
3f12fcef 49 LTTNG_BUILD_BUG_ON(condition); \
44d13f19 50 else \
3f12fcef 51 LTTNG_BUG_ON(condition); \
44d13f19
MD
52 } while (0)
53
54#endif
This page took 0.02571 seconds and 4 git commands to generate.