aboutsummaryrefslogtreecommitdiff
path: root/util.h
blob: 3c13cc4f3f7f6dfb38418b0a99e0b035c3c9641a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* This file is part of libbrandt.
 * Copyright (C) 2016 GNUnet e.V.
 *
 * libbrandt is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * libbrandt.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file util.h
 * @brief Interface for the common utility functions.
 * @author Markus Teich
 */

#ifndef _BRANDT_UTIL_H
#define _BRANDT_UTIL_H

void setlog (FILE *stream);
void eprintf (const char *fmt, ...);
void weprintf (const char *fmt, ...);

#undef brandt_assert
#undef brandt_assert_perror
#undef brandt_assert_gpgerr

#ifdef NDEBUG

#define brandt_assert(expr) do { \
		(expr) ? (void)(0) : eprintf ( \
		    "Assertion failed in file %s line %d function %s: %s", \
		    __FILE__, \
		    __LINE__, \
		    __PRETTY_FUNCTION__, \
		    (# expr)); \
} while (0)

#define brandt_assert_perror(errnum) do { \
		!(errnum) ? (void)(0) : eprintf ( \
		    "Assertion failed in file %s line %d function %s:", \
		    __FILE__, \
		    __LINE__, \
		    __PRETTY_FUNCTION__); \
} while (0)

#define brandt_assert_gpgerr(errnum) do { \
		!(errnum) ? (void)(0) : eprintf ( \
		    "Assertion failed in file %s line %d function %s: %s", \
		    __FILE__, \
		    __LINE__, \
		    __PRETTY_FUNCTION__, \
		    gcry_strerror ((errnum))); \
} while (0)

#define DP(point) ((void)(gcry_log_debugpnt (# point, point, ec_ctx)))
#define DM(mpi) ((void)(gcry_log_debugmpi (# mpi, mpi)))
#define DS(sexp) ((void)(gcry_log_debugsxp (# sexp, sexp)))

#else /* ifdef NDEBUG */

#define brandt_assert(expr)          ((void)(expr))
#define brandt_assert_perror(errnum) ((void)(errnum))
#define brandt_assert_gpgerr(errnum) ((void)(errnum))

#endif /* ifdef NDEBUG */

#endif /* ifndef _BRANDT_UTIL_H */