forked from brunorijsman/openssl-qkd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qkd_debug.c
55 lines (49 loc) · 1.32 KB
/
qkd_debug.c
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
/**
* qkd_debug.c
*
* Common code for debugging.
*
* (c) 2019 Bruno Rijsman, All Rights Reserved.
* See LICENSE for licensing information.
*/
#include "qkd_debug.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* TODO: Turn debug on or off using environment variable */
static bool debug = true;
static void print_location(const char *file, int line, const char *func)
{
fprintf(stderr, "[%s:%d (%s)] ", file, line, func);
}
void _QKD_error(const char *file, int line, const char *func, const char *format, ...)
{
va_list args;
print_location(file, line, func);
va_start(args, format);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
va_end(args);
}
void _QKD_error_with_errno(const char *file, int line, const char *func, const char *format, ...)
{
va_list args;
print_location(file, line, func);
va_start(args, format);
vfprintf(stderr, format, args);
fprintf(stderr, ": %s\n", strerror(errno));
va_end(args);
}
void _QKD_debug(const char *file, int line, const char *func, const char *format, ...)
{
if (debug) {
va_list args;
print_location(file, line, func);
va_start(args, format);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
va_end(args);
}
}