summaryrefslogtreecommitdiff
path: root/test/testprog.cc
blob: dbfb6653388d01cb115f4a06e5df7e052a7dd8cb (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
#include <iostream>
#include <fstream>
#include <string>

extern const char **environ; // see 'man environ'

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 == "throw")
	{
		throw "ouch";
	}

	return 0;
}