summaryrefslogtreecommitdiff
path: root/test/testprog.cc
blob: faf14989b4e4dcb2859ea5c8943a2d1d2dbe3339 (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
46
47
48
49
50
51
52
53
#include <iostream>
#include <fstream>
#include <string>
#include <signal.h>

int main(int argc, const char* argv[])
{
	if(argc < 2)
	{
		return 0;
	}

	std::string cmd = argv[1];

	if(cmd == "envdump")
	{
		if(argc < 3)
		{
			return 0;
		}
		std::ofstream ostrm(argv[2], std::ios::binary);
		for(auto current = environ; *current; ++current)
		{
			ostrm << (*current) << "\n";
		}
	}

	if(cmd == "retval")
	{
		if(argc < 3)
		{
			return 0;
		}
		return std::stoi(argv[2]);
	}

	if(cmd == "abort")
	{
		abort();
	}

	if(cmd == "segfault")
	{
		raise(SIGSEGV);
	}

	if(cmd == "throw")
	{
		throw "ouch";
	}

	return 0;
}