libspades
Ace of Spades library
log.h
1#ifndef LIBSPADES_LOG_H
2#define LIBSPADES_LOG_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#ifdef _MSC_VER
8#define __restrict__ __restrict
9#elif !defined(__GNUC__)
10#define __restrict__
11#endif
12
13#include "datatypes.h"
14
15void libspades_log(const char *__restrict__ format, ...);
16char *libspades_print_packet(const uint8_t *data, size_t dataLength);
17
18/* More or less assert with an error message. */
19#define LIBSPADES_FORCE_ASSERT(condition, action, printf_args) \
20 do { \
21 if (!(condition)) { \
22 libspades_log printf_args; \
23 action; \
24 } \
25 } while (0)
26
27/* If you do not trust the server to have correct behaviour, I would recommend enabling this. */
28#ifndef NDEBUG
29#define LIBSPADES_ASSERT(condition, action, printf_args) LIBSPADES_FORCE_ASSERT(condition, action, printf_args)
30#else
31#define LIBSPADES_ASSERT(condition, action, printf_args) ((void)0)
32#endif
33
34#ifdef __cplusplus
35}
36#endif
37#endif