summaryrefslogtreecommitdiff
path: root/drain.ha
blob: a76184b030ab08996d8e8138a8095c30922a0902 (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
use errors;
use fs;
use io;
use os;
use fmt;

fn drain(path: str) []u8 = {
	const file = match (os::open(path)) {
	case let file: io::file =>
		yield file;
	case errors::noaccess =>
		fmt::fatalf("error opening {}: access denied", path);
	case let err: fs::error =>
		fmt::fatalf("error opening {}: {}", path, fs::strerror(err));
	};
	defer io::close(file)!;
	const buf = match (io::drain(file)) {
	case let buf: []u8 =>
		yield buf;
	case let err: io::error =>
		fmt::fatalf("io::drain failed: {}", io::strerror(err));
	};
	return buf;
};