summaryrefslogtreecommitdiff
path: root/src/user/lib/fwik/io/Dir.cpp
blob: cfcc77b283ff345c7c160343096b7369197e6488 (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
#include <IO/Dir.h>

Dir::Dir(const Node &n) : Node(n) {
	_init();
}

Dir::Dir(FILE f) : Node(f) {
	_init();
	if (error == E_INVALID_TYPE) libc::close(fd);
}

Dir::Dir(const char* filename, int mode) : Node(filename, mode) {
	_init();
	if (error == E_INVALID_TYPE) libc::close(fd);
}

void Dir::_init() {
	if (error < 0) return;
	pos = 0;
	if ((info.type & FT_DIR) == 0) {
		error = E_INVALID_TYPE;
	}
}

Dir::~Dir() {
}

String Dir::read_ent() {
	char buf[256];
	int l = libc::read(fd, pos, 256, buf);
	if (l > 0) {
		pos++;
		return String(buf, l);
	} else {
		return "";
	}
}