summaryrefslogtreecommitdiff
path: root/test/testprog.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2023-01-20 08:37:29 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2023-01-20 09:02:45 +0100
commita5585150f0ff8d27ddd22792f521f1374a3eedd8 (patch)
tree3bb442e835502d452ebe5137ad7fca5f5156bb5f /test/testprog.cc
parent3cbadb8f5c55020ece96fab0fc8f4f51da01888e (diff)
Add env to execute function.
Diffstat (limited to 'test/testprog.cc')
-rw-r--r--test/testprog.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/testprog.cc b/test/testprog.cc
new file mode 100644
index 0000000..dbfb665
--- /dev/null
+++ b/test/testprog.cc
@@ -0,0 +1,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;
+}