aboutsummaryrefslogtreecommitdiff
path: root/lib/tar/src/iterator.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-01 14:55:58 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-01 17:28:39 +0200
commit3f7f3654d243275332d964f9ecbb79f9eb83a5d1 (patch)
treee46bfea72edff431092bb124bff948976358918a /lib/tar/src/iterator.c
parent665221e904df597925fc411d443802b20758b71f (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/tar/src/iterator.c')
-rw-r--r--lib/tar/src/iterator.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/tar/src/iterator.c b/lib/tar/src/iterator.c
index 9a6b9f7..0940905 100644
--- a/lib/tar/src/iterator.c
+++ b/lib/tar/src/iterator.c
@@ -158,7 +158,6 @@ static void strm_destroy(sqfs_object_t *obj)
static int it_next(dir_iterator_t *it, dir_entry_t **out)
{
tar_iterator_t *tar = (tar_iterator_t *)it;
- dir_entry_t *ent;
int ret;
*out = NULL;
@@ -202,28 +201,26 @@ retry:
return tar->state;
}
- ent = calloc(1, sizeof(*ent) + strlen(tar->current.name) + 1);
- if (ent == NULL) {
+ *out = dir_entry_create(tar->current.name);
+ if ((*out) == NULL) {
tar->state = SQFS_ERROR_ALLOC;
return tar->state;
}
- ent->mtime = tar->current.mtime;
- ent->rdev = tar->current.devno;
- ent->uid = tar->current.uid;
- ent->gid = tar->current.gid;
- ent->mode = tar->current.mode;
- strcpy(ent->name, tar->current.name);
+ (*out)->mtime = tar->current.mtime;
+ (*out)->rdev = tar->current.devno;
+ (*out)->uid = tar->current.uid;
+ (*out)->gid = tar->current.gid;
+ (*out)->mode = tar->current.mode;
if (tar->current.is_hard_link) {
- ent->mode = (S_IFLNK | 0777);
- ent->flags |= DIR_ENTRY_FLAG_HARD_LINK;
+ (*out)->mode = (S_IFLNK | 0777);
+ (*out)->flags |= DIR_ENTRY_FLAG_HARD_LINK;
}
- if (S_ISREG(ent->mode))
- ent->size = tar->current.actual_size;
+ if (S_ISREG((*out)->mode))
+ (*out)->size = tar->current.actual_size;
- *out = ent;
return 0;
fail:
tar->state = ret < 0 ? SQFS_ERROR_IO : 1;