Releasing debian version 4.04+dfsg-9.
[syslinux-debian/hramrach.git] / core / fs / readdir.c
blobd071affdc7421c5413e877de20aee2768d71f64f
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/dirent.h>
4 #include "fs.h"
5 #include "core.h"
7 /*
8 * Open a directory
9 */
10 DIR *opendir(const char *path)
12 int rv;
13 struct file *file;
15 rv = searchdir(path);
16 if (rv < 0)
17 return NULL;
19 file = handle_to_file(rv);
21 if (file->inode->mode != DT_DIR) {
22 _close_file(file);
23 return NULL;
26 return (DIR *)file;
30 * Read one directory entry at one time.
32 struct dirent *readdir(DIR *dir)
34 static struct dirent buf;
35 struct file *dd_dir = (struct file *)dir;
36 int rv = -1;
38 if (dd_dir) {
39 if (dd_dir->fs->fs_ops->readdir) {
40 rv = dd_dir->fs->fs_ops->readdir(dd_dir, &buf);
44 return rv < 0 ? NULL : &buf;
48 * Close a directory
50 int closedir(DIR *dir)
52 struct file *dd_dir = (struct file *)dir;
53 _close_file(dd_dir);
54 return 0;