diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-01 14:55:58 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-01 17:28:39 +0200 |
commit | 3f7f3654d243275332d964f9ecbb79f9eb83a5d1 (patch) | |
tree | e46bfea72edff431092bb124bff948976358918a /lib/io/src/unix | |
parent | 665221e904df597925fc411d443802b20758b71f (diff) |
libio: split dir_entry_t from dir_iterator_t, add create helper
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/src/unix')
-rw-r--r-- | lib/io/src/unix/dir_iterator.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/lib/io/src/unix/dir_iterator.c b/lib/io/src/unix/dir_iterator.c index 7154ec9..afbf0c0 100644 --- a/lib/io/src/unix/dir_iterator.c +++ b/lib/io/src/unix/dir_iterator.c @@ -76,8 +76,6 @@ static int dir_read_link(dir_iterator_t *base, char **out) static int dir_next(dir_iterator_t *base, dir_entry_t **out) { unix_dir_iterator_t *it = (unix_dir_iterator_t *)base; - dir_entry_t *decoded; - size_t len; *out = NULL; if (it->state != 0) @@ -102,29 +100,25 @@ static int dir_next(dir_iterator_t *base, dir_entry_t **out) return it->state; } - len = strlen(it->ent->d_name); - - decoded = alloc_flex(sizeof(*decoded), 1, len + 1); - if (decoded == NULL) { + *out = dir_entry_create(it->ent->d_name); + if ((*out) == NULL) { it->state = SQFS_ERROR_ALLOC; return it->state; } - memcpy(decoded->name, it->ent->d_name, len); - decoded->mtime = it->sb.st_mtime; - decoded->dev = it->sb.st_dev; - decoded->rdev = it->sb.st_rdev; - decoded->uid = it->sb.st_uid; - decoded->gid = it->sb.st_gid; - decoded->mode = it->sb.st_mode; + (*out)->mtime = it->sb.st_mtime; + (*out)->dev = it->sb.st_dev; + (*out)->rdev = it->sb.st_rdev; + (*out)->uid = it->sb.st_uid; + (*out)->gid = it->sb.st_gid; + (*out)->mode = it->sb.st_mode; if (S_ISREG(it->sb.st_mode)) - decoded->size = it->sb.st_size; + (*out)->size = it->sb.st_size; - if (decoded->dev != it->device) - decoded->flags |= DIR_ENTRY_FLAG_MOUNT_POINT; + if ((*out)->dev != it->device) + (*out)->flags |= DIR_ENTRY_FLAG_MOUNT_POINT; - *out = decoded; return it->state; } |