Adding upstream version 6.03~pre2+dfsg.
[syslinux-debian/hramrach.git] / core / fs / readdir.c
blob546a704a0491af9732d6e99ce516561ee88ad9b7
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <sys/dirent.h>
5 #include "fs.h"
6 #include "core.h"
8 /*
9 * Open a directory
11 __export DIR *opendir(const char *path)
13 int rv;
14 struct file *file;
16 rv = searchdir(path, O_RDONLY|O_DIRECTORY);
17 if (rv < 0)
18 return NULL;
20 file = handle_to_file(rv);
22 if (file->inode->mode != DT_DIR) {
23 _close_file(file);
24 return NULL;
27 return (DIR *)file;
31 * Read one directory entry at one time.
33 __export struct dirent *readdir(DIR *dir)
35 static struct dirent buf;
36 struct file *dd_dir = (struct file *)dir;
37 int rv = -1;
39 if (dd_dir) {
40 if (dd_dir->fs->fs_ops->readdir) {
41 rv = dd_dir->fs->fs_ops->readdir(dd_dir, &buf);
45 return rv < 0 ? NULL : &buf;
49 * Close a directory
51 __export int closedir(DIR *dir)
53 struct file *dd_dir = (struct file *)dir;
54 _close_file(dd_dir);
55 return 0;