summaryrefslogtreecommitdiff
path: root/demo.cc
blob: 62bdeedfa37075b24d29803629a025ebfb6c31c2 (plain) (blame)
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
#include <cstdlib>
#include <dux/io.h>
#include <dux/thr.h>
#include <iostream>

int main() {
	::std::cout << "dux " << dux_api << '.' << dux_ext << ", demo" << ::std::endl;

	::dux_err err = ::dux_err_oky;

	auto const chkerr = [&err](char const * const msg) noexcept {
		if (err != ::dux_err_oky) {
			::std::cout << msg << ": " << ::dux_errmsg(err) << ::std::endl;
			::std::exit(EXIT_FAILURE);
		}
	};

	err = ::dux_crtdir("testdir",0755u);
	chkerr("unable to create directory");

	::dux_fil * fil = nullptr;

	err = ::dux_crt(&fil,"testdir/dux-demo-file",0644u);
	chkerr("unable to create file");

	err = ::dux_wrtstr(fil,
		"static void msg(void);\n"
		"\n"
		"int main(void) {\n"
		"\tmsg();\n"
		"\treturn 0x45;\n"
		"}\n"
	);
	chkerr("unable to write to file");

	err = ::dux_cls(fil);
	chkerr("unable to close file");
}