aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/include/assert.h
blob: 1b2bda2adeb8bc4daf414dda0d19e0e522cea667 (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
/*
 * PSn00bSDK assert macro and internal logging
 * (C) 2022 spicyjpeg - MPL licensed
 *
 * Note that the _sdk_log() macro is used internally by PSn00bSDK to output
 * debug messages and warnings.
 */

#ifndef __ASSERT_H
#define __ASSERT_H

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

void _assert_abort(const char *file, int line, const char *expr);

#ifdef __cplusplus
}
#endif

#ifdef NDEBUG

#define assert(expr)
#define _sdk_log(fmt, ...)

#else

#define assert(expr) \
	((expr) ? ((void) 0) : _assert_abort(__FILE__, __LINE__, #expr))

#ifdef SDK_LIBRARY_NAME
#define _sdk_log(fmt, ...) printf(SDK_LIBRARY_NAME ": " fmt, ##__VA_ARGS__)
#else
#define _sdk_log(fmt, ...) printf(fmt, ##__VA_ARGS__)
#endif

#endif

#endif