aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/include/assert.h
blob: 12212afb508c5c25da8a84e0e145269e98b8609d (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
/*
 * 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>

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

#ifdef NDEBUG

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

#else

#define assert(expr) { \
	if (!(expr)) _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