summaryrefslogtreecommitdiffstats
path: root/src/ustar.c
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-14 18:58:18 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-04-15 18:03:18 (EDT)
commit3c3612d0eaec5f9b6c3c1596f43b395ad5cdcd80 (patch)
tree947861434169a8b6f731e9550b793631eb181bd0 /src/ustar.c
parentf36acc8cfe90ff98ad39e9d84b0270890f442273 (diff)
ustar: Fix read buffer
Diffstat (limited to 'src/ustar.c')
-rw-r--r--src/ustar.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/ustar.c b/src/ustar.c
index f403524..0a508f5 100644
--- a/src/ustar.c
+++ b/src/ustar.c
@@ -50,6 +50,7 @@ struct _opkg_opk_ustar_header {
struct opkg_opk_ustar {
struct opkg_opk_gzip *gzip;
int32_t data_size_remaining;
+ unsigned char read_record[OPKG_OPK_USTAR_RECORD_SIZE];
};
struct opkg_opk_ustar *
@@ -103,23 +104,22 @@ int
opkg_opk_ustar_list(struct opkg_opk_ustar *ustar,
struct opkg_opk_ustar_member *member)
{
- static struct _opkg_opk_ustar_header record;
+ static struct _opkg_opk_ustar_header header;
int ret;
- if ((ret =_opkg_opk_ustar_next(ustar, &record)) != OPKG_OPK_OK) {
+ if ((ret =_opkg_opk_ustar_next(ustar, &header)) != OPKG_OPK_OK) {
return ret; /* Error or end of archive */
}
- if (record.prefix[0] != '\0') {
- sprintf(member->name, "%s/%s", record.prefix, record.name);
+ if (header.prefix[0] != '\0') {
+ sprintf(member->name, "%s/%s", header.prefix, header.name);
} else {
- memcpy(member->name, record.name, sizeof(record.name));
- member->name[sizeof(record.name)] = '\0';
+ memcpy(member->name, header.name, sizeof(header.name));
+ member->name[sizeof(header.name)] = '\0';
}
while (ustar->data_size_remaining > 0) {
- if (opkg_opk_ustar_read(ustar, (char *) &record, NULL) ==
- OPKG_OPK_ERROR) {
+ if (opkg_opk_ustar_read(ustar, NULL, NULL) == OPKG_OPK_ERROR) {
return OPKG_OPK_ERROR;
}
}
@@ -130,22 +130,22 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar,
int
opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member)
{
- static struct _opkg_opk_ustar_header record;
+ static struct _opkg_opk_ustar_header header;
static unsigned char name[OPKG_OPK_USTAR_NAME_MAX_LEN];
int ret;
for (;;) {
- if ((ret =_opkg_opk_ustar_next(ustar, &record)) != OPKG_OPK_OK)
+ if ((ret =_opkg_opk_ustar_next(ustar, &header)) != OPKG_OPK_OK)
{
return OPKG_OPK_ERROR; /* Error or end (not found) */
}
- if (record.prefix[0] != '\0') {
- sprintf((char *) name, "%s/%s", record.prefix,
- record.name);
+ if (header.prefix[0] != '\0') {
+ sprintf((char *) name, "%s/%s", header.prefix,
+ header.name);
} else {
- memcpy(name, record.name, sizeof(record.name));
- name[sizeof(record.name)] = '\0';
+ memcpy(name, header.name, sizeof(header.name));
+ name[sizeof(header.name)] = '\0';
}
if (strcmp((char *) name, member) == 0) {
@@ -155,8 +155,8 @@ opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member)
}
while (ustar->data_size_remaining > 0) {
- if (opkg_opk_ustar_read(ustar, (char *) &record, NULL)
- == OPKG_OPK_ERROR) {
+ if (opkg_opk_ustar_read(ustar, NULL, NULL) ==
+ OPKG_OPK_ERROR) {
return OPKG_OPK_ERROR;
}
}
@@ -166,13 +166,13 @@ opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member)
}
int
-opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char *buffer, size_t *size)
+opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char **buffer, size_t *size)
{
if (ustar->data_size_remaining == 0) {
return OPKG_OPK_END;
}
- switch (opkg_opk_gzip_read(ustar->gzip, buffer)) {
+ switch (opkg_opk_gzip_read(ustar->gzip, ustar->read_record)) {
case OPKG_OPK_OK:
break;
case OPKG_OPK_END:
@@ -180,6 +180,9 @@ opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char *buffer, size_t *size)
return OPKG_OPK_ERROR;
}
+ if (buffer != NULL) {
+ *buffer = ustar->read_record;
+ }
if (ustar->data_size_remaining >= OPKG_OPK_USTAR_RECORD_SIZE) {
if (size != NULL) {
*size = OPKG_OPK_USTAR_RECORD_SIZE;