summaryrefslogtreecommitdiff
path: root/corebinutils/sh/testcmd.c
blob: b8b8e7a4ee1406d86f387131ea33b800d0d7db71 (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
/*
 * Reuse the standalone test(1) parser as the shell builtin entry point.
 * The external source now exports main() and exits on syntax errors, so
 * provide a wrapper that maps its process-exit path back to a builtin
 * return value.
 */

#include <setjmp.h>
#include <stdio.h>

static jmp_buf testcmd_jmp;
static int testcmd_status;

static void
testcmd_exit(int status)
{
	testcmd_status = status;
	fflush(NULL);
	longjmp(testcmd_jmp, 1);
}

#define exit testcmd_exit
#define main testcmd_main
#include "../test/test.c"
#undef main
#undef exit

int
testcmd(int argc, char **argv)
{
	if (setjmp(testcmd_jmp) != 0)
		return testcmd_status;
	return testcmd_main(argc, argv);
}