kbd: use a better get_key method
[thunix.git] / fs / dir.c
blob739d8c91e368330b523acb76b014976a32dd1434
1 #include <stdio.h>
2 #include <string.h>
3 #include <malloc.h>
4 #include <fs.h>
5 #include <dirent.h>
6 #include <err.h>
8 /* for relative path searching */
9 DIR *this_dir;
11 DIR *opendir(const char *path)
13 struct inode *inode;
14 DIR *dir;
16 inode = namei(path, 0);
17 if (IS_ERR_OR_NULL(inode))
18 return inode ? ERR_CAST(inode) : ERR_PTR(-ENOENT);
20 dir = malloc(sizeof(*dir));
21 if (!dir)
22 return ERR_PTR(-ENOMEM);
23 dir->dd_dir = malloc(sizeof(struct file));
24 if (!dir->dd_dir) {
25 free(dir);
26 return ERR_PTR(-ENOMEM);
28 dir->dd_dir->inode = inode;
29 dir->dd_dir->fs = inode->i_fs;
30 dir->dd_dir->offset = 0;
31 dir->dd_dir->f_op = inode->i_fop;
33 return dir;