aboutsummaryrefslogtreecommitdiffstats
path: root/src/libabc-private.h
blob: 7c9ad930efaf3d6b319433b70c0aecc5eb0fe8ae (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
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
/*
  libabc - something with abc

  Copyright (C) 2011 Someone <someone@example.com>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library 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
  Lesser General Public License for more details.
*/

#ifndef _LIBABC_PRIVATE_H_
#define _LIBABC_PRIVATE_H_

#include <stdbool.h>
#include <syslog.h>

#include <abc/libabc.h>

static inline void __attribute__((always_inline, format(printf, 2, 3)))
abc_log_null(struct abc_ctx *ctx, const char *format, ...) {}

#define abc_log_cond(ctx, prio, arg...) \
  do { \
    if (abc_get_log_priority(ctx) >= prio) \
      abc_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
  } while (0)

#ifdef ENABLE_LOGGING
#  ifdef ENABLE_DEBUG
#    define dbg(ctx, arg...) abc_log_cond(ctx, LOG_DEBUG, ## arg)
#  else
#    define dbg(ctx, arg...) abc_log_null(ctx, ## arg)
#  endif
#  define info(ctx, arg...) abc_log_cond(ctx, LOG_INFO, ## arg)
#  define err(ctx, arg...) abc_log_cond(ctx, LOG_ERR, ## arg)
#else
#  define dbg(ctx, arg...) abc_log_null(ctx, ## arg)
#  define info(ctx, arg...) abc_log_null(ctx, ## arg)
#  define err(ctx, arg...) abc_log_null(ctx, ## arg)
#endif

#ifndef HAVE_SECURE_GETENV
#  ifdef HAVE___SECURE_GETENV
#    define secure_getenv __secure_getenv
#  else
#    error neither secure_getenv nor __secure_getenv is available
#  endif
#endif

#define ABC_EXPORT __attribute__ ((visibility("default")))

void abc_log(struct abc_ctx *ctx,
           int priority, const char *file, int line, const char *fn,
           const char *format, ...)
           __attribute__((format(printf, 6, 7)));

#endif