From a7bf75ebdb991092dd9165db99acfa034166fb43 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 15 Jul 2023 13:33:51 +0200 Subject: Implement pen_file_ro method in native dir iterators Signed-off-by: David Oberhollenzer --- lib/io/src/unix/dir_iterator.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'lib/io/src/unix') diff --git a/lib/io/src/unix/dir_iterator.c b/lib/io/src/unix/dir_iterator.c index 12e2ac1..d2ae011 100644 --- a/lib/io/src/unix/dir_iterator.c +++ b/lib/io/src/unix/dir_iterator.c @@ -8,6 +8,7 @@ #include "io/dir_iterator.h" #include "util/util.h" #include "sqfs/error.h" +#include "sqfs/io.h" #include #include @@ -126,11 +127,30 @@ static void dir_ignore_subdir(dir_iterator_t *it) (void)it; } -static int dir_open_file_ro(dir_iterator_t *it, sqfs_istream_t **out) +static int dir_open_file_ro(dir_iterator_t *base, sqfs_istream_t **out) { - (void)it; + unix_dir_iterator_t *it = (unix_dir_iterator_t *)base; + int fd, ret; + *out = NULL; - return SQFS_ERROR_UNSUPPORTED; + if (it->state < 0) + return it->state; + + if (it->state > 0 || it->ent == NULL) + return SQFS_ERROR_NO_ENTRY; + + fd = openat(dirfd(it->dir), it->ent->d_name, O_RDONLY); + if (fd < 0) + return SQFS_ERROR_IO; + + ret = sqfs_istream_open_handle(out, it->ent->d_name, + fd, SQFS_FILE_OPEN_READ_ONLY); + if (ret != 0) { + int err = errno; + close(fd); + errno = err; + } + return ret; } static int dir_read_xattr(dir_iterator_t *it, sqfs_xattr_t **out) -- cgit v1.2.3