aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/options/internal/include/bits/ensure.h
blob: f75a2e9b7f377159c03fa357caa2b0d98e93e49f (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

#ifndef MLIBC_ENSURE_H
#define MLIBC_ENSURE_H

#ifdef __cplusplus
extern "C" {
#endif

#ifndef __MLIBC_ABI_ONLY

void __ensure_fail(const char *assertion, const char *file, unsigned int line,
		const char *function);

void __ensure_warn(const char *assertion, const char *file, unsigned int line,
		const char *function);

#endif /* !__MLIBC_ABI_ONLY */

#define __ensure(assertion) do { if(!(assertion)) \
		__ensure_fail(#assertion, __FILE__, __LINE__, __func__); } while(0)

#define MLIBC_UNIMPLEMENTED() __ensure_fail("Functionality is not implemented", \
		__FILE__, __LINE__, __func__)

#define MLIBC_MISSING_SYSDEP() __ensure_warn("Library function fails due to missing sysdep", \
		__FILE__, __LINE__, __func__)

#define MLIBC_CHECK_OR_ENOSYS(sysdep, ret) ({ \
			if (!(sysdep)) { \
				__ensure_warn("Library function fails due to missing sysdep", \
					__FILE__, __LINE__, __func__); \
				errno = ENOSYS; \
				return (ret); \
			} \
			sysdep; \
		})

#define MLIBC_STUB_BODY { MLIBC_UNIMPLEMENTED(); __builtin_unreachable(); }

#ifdef __cplusplus
}
#endif

#endif // MLIBC_ENSURE_H