Changeset View
Changeset View
Standalone View
Standalone View
stand/libsa/readdir.c
Show All 28 Lines | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include "stand.h" | #include "stand.h" | ||||
struct dirent * | struct dirent * | ||||
readdirfd(int fd) | readdirfd(int fd) | ||||
{ | { | ||||
static struct dirent dir; /* XXX not thread safe */ | static struct dirent dir; /* XXX not thread safe */ | ||||
struct open_file *f = &files[fd]; | struct open_file *f; | ||||
if ((unsigned)fd >= SOPEN_MAX || !(f->f_flags & F_READ)) { | f = fd2open_file(fd); | ||||
if (f == NULL || !(f->f_flags & F_READ)) { | |||||
errno = EBADF; | errno = EBADF; | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
if (f->f_flags & F_RAW) { | if (f->f_flags & F_RAW) { | ||||
errno = EIO; | errno = EIO; | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
errno = (f->f_ops->fo_readdir)(f, &dir); | errno = (f->f_ops->fo_readdir)(f, &dir); | ||||
if (errno) | if (errno) | ||||
return (NULL); | return (NULL); | ||||
return (&dir); | return (&dir); | ||||
} | } |