summaryrefslogtreecommitdiff
path: root/src/user/lib/fwik/io/Dir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib/fwik/io/Dir.cpp')
-rw-r--r--src/user/lib/fwik/io/Dir.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/user/lib/fwik/io/Dir.cpp b/src/user/lib/fwik/io/Dir.cpp
new file mode 100644
index 0000000..cfcc77b
--- /dev/null
+++ b/src/user/lib/fwik/io/Dir.cpp
@@ -0,0 +1,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 "";
+ }
+}