summaryrefslogtreecommitdiff
path: root/src/__checked_i.c
blob: f3b62bcf12c280279a5d5d9af87d080199cd1c32 (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
#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
#include "_assert.h"

#define F(fn) (int(*)())(fn)

int __checked_i(const char *file, const char *func, unsigned long long line, int (*fn)(), ...)
{
	va_list ap;
	int ret = -1;

	__checked_call.func = (char*)func;
	__checked_call.file = (char*)file;
	__checked_call.line = line;

	va_start(ap, fn);

	if (fn == F(isalpha)
		|| fn == F(isdigit)
		|| fn == F(isupper)
		|| fn == F(islower)
		|| fn == F(toupper)
		|| fn == F(tolower)
		) {
		int arg = va_arg(ap, int);
		ret = fn(arg);
	}

	va_end(ap);

	__checked_call.func = NULL;
	__checked_call.file = NULL;
	__checked_call.line = 0;

	return ret;
}

/*
STDC(0)
*/