celtic / akari

My attempt at bringing light to operating system development.

This URL has Read+Write access

akari / dirent.cpp.unused
100644 34 lines (24 sloc) 0.55 kb
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
#include <dirent.hpp>
#include <memory.hpp>
#include <string.hpp>
 
DIR *opendir(const char *name) {
fs_node_t *base = fs_root;
 
DIR *new_dir = (DIR *)kmalloc(sizeof(DIR));
new_dir->base = base;
new_dir->next_index = 0;
 
return new_dir;
}
 
struct dirent *readdir(DIR *dir) {
static struct dirent dirent;
 
dirent_t *node = readdir_fs(dir->base, dir->next_index);
if (node == 0)
return 0;
dir->next_index++;
 
strcpy(dirent.name, node->name);
dirent.ino = node->ino;
 
return &dirent;
}
 
int closedir(DIR *dir) {
kfree(dir);
return 0;
}