aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/file_drop.zc
blob: 0c0738ad8576baf7922c80cdb66d521f47c6993b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
namespace;
// std.File: Host.open gives an owned file whose drop closes the descriptor at its block end (a write to it then writes nothing)
include rt, std;
fn main() {
	int fd = 0 - 1;
	{
		std.File* f = std.Host.open("/tmp/zc-file-drop.txt", 1);
		fd = f.fd;
		rt.put_n(f.write("hello")); rt.put_c(' ');
		rt.put_n(rt.syscall(rt.SYS_WRITE, fd, "!", 1)); rt.put_c(' ');
	}
	rt.put_n(rt.syscall(rt.SYS_WRITE, fd, "?", 1) <= 0); rt.put_c(' ');
	char* s = rt.readfile("/tmp/zc-file-drop.txt");
	rt.put_s(s); rt.put_c(' ');
	rt.free(s);
	std.File* g = std.Host.open("/tmp/zc-no-such-dir/x", 1);
	rt.put_n(g == 0); rt.put_c(10);
	return 0;
}