summaryrefslogblamecommitdiff
path: root/src/user/lib/fwik/io/Dir.cpp
blob: cfcc77b283ff345c7c160343096b7369197e6488 (plain) (tree)




































                                                                 
#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 "";
	}
}