summaryrefslogtreecommitdiff
path: root/test/testprog.cc
blob: 2b6619e8d6ea3f8548c66d6306abca12b650dfb6 (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 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;
}