summaryrefslogtreecommitdiffstats
path: root/src/debug.h
blob: 81ed2475d8e42fdf53216572eee291d824c5646f (plain)
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
/* Copyright (C) 2014 GSS-NTLMSSP contributors, see COPYING for license */

#ifndef _GSSNTLMSSP_DEBUG_H_
#define _GSSNTLMSSP_DEBUG_H_

#include <stdbool.h>
#include <time.h>

extern bool gssntlm_debug_initialized;
extern bool gssntlm_debug_enabled;

void gssntlm_debug_init(void);
void gssntlm_debug_printf(const char *fmt, ...);

#define unlikely(x) __builtin_expect(!!(x), 0)

static inline int debug_gss_errors(const char *function,
                                   const char *file,
                                   unsigned int line,
                                   unsigned int maj,
                                   unsigned int min)
{
    if (unlikely(gssntlm_debug_initialized == false)) {
        gssntlm_debug_init();
    }
    if (unlikely(gssntlm_debug_enabled == true)) {
        gssntlm_debug_printf("[%ld] %s: %s() @ %s:%u [%u:%u]\n",
                             (long)time(NULL),
                             GSS_ERROR(maj) ? "ERROR" : "ALLOK",
                             function, file, line, maj, min);
    }
    return 0;
}
#define DEBUG_GSS_ERRORS(maj, min) \
    debug_gss_errors(__FUNCTION__, __FILE__, __LINE__, maj, min)

#endif /* _GSSNTLMSSP_DEBUG_H_ */