summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ustar.c41
-rw-r--r--src/ustar.h7
2 files changed, 43 insertions, 5 deletions
diff --git a/src/ustar.c b/src/ustar.c
index 0eda87a..7fa64e2 100644
--- a/src/ustar.c
+++ b/src/ustar.c
@@ -52,7 +52,7 @@ struct opkg_opk_ustar {
struct opkg_opk_gzip *gzip;
uint64_t data_size_remaining;
struct _opkg_opk_ustar_header header;
- char read_record[OPKG_OPK_USTAR_RECORD_SIZE];
+ char record[OPKG_OPK_USTAR_RECORD_SIZE];
};
struct opkg_opk_ustar *
@@ -98,8 +98,8 @@ _opkg_opk_ustar_next(struct opkg_opk_ustar *ustar)
}
/* Check for end of archive. */
- memset(ustar->read_record, 0, OPKG_OPK_USTAR_RECORD_SIZE);
- if (memcmp(&ustar->header, ustar->read_record,
+ memset(ustar->record, 0, OPKG_OPK_USTAR_RECORD_SIZE);
+ if (memcmp(&ustar->header, ustar->record,
OPKG_OPK_USTAR_RECORD_SIZE) == 0) {
return OPKG_OPK_END;
}
@@ -238,7 +238,7 @@ opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char **buffer, size_t *size)
}
/* Decompress next data record. */
- switch (opkg_opk_gzip_read(ustar->gzip, ustar->read_record)) {
+ switch (opkg_opk_gzip_read(ustar->gzip, ustar->record)) {
case OPKG_OPK_OK:
break;
case OPKG_OPK_END:
@@ -249,7 +249,7 @@ opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char **buffer, size_t *size)
/* Store buffer and size in caller's memory and update remaining size.
*/
if (buffer != NULL) {
- *buffer = ustar->read_record;
+ *buffer = ustar->record;
}
if (ustar->data_size_remaining >= OPKG_OPK_USTAR_RECORD_SIZE) {
if (size != NULL) {
@@ -320,6 +320,37 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
return OPKG_OPK_OK;
}
+int
+opkg_opk_ustar_get_buffer(struct opkg_opk_ustar *ustar, char **buffer,
+ size_t *size)
+{
+ *buffer = ustar->record;
+ *size = sizeof(ustar->record);
+ return OPKG_OPK_OK;
+}
+
+int
+opkg_opk_ustar_write_data(struct opkg_opk_ustar *ustar, size_t size)
+{
+ /* Sanity check. */
+ if (size > ustar->data_size_remaining ||
+ size > OPKG_OPK_USTAR_RECORD_SIZE) {
+ return OPKG_OPK_ERROR;
+ }
+
+ /* Zero out end of record. */
+ memset(ustar->record + size, 0, OPKG_OPK_USTAR_RECORD_SIZE - size);
+
+ /* Write to gzip stream. */
+ if (opkg_opk_gzip_write(ustar->gzip, ustar->record,
+ OPKG_OPK_USTAR_RECORD_SIZE, 0) != OPKG_OPK_OK) {
+ return OPKG_OPK_ERROR;
+ }
+
+ ustar->data_size_remaining -= size;
+ return OPKG_OPK_OK;
+}
+
void
opkg_opk_ustar_free(struct opkg_opk_ustar *ustar)
{
diff --git a/src/ustar.h b/src/ustar.h
index 1337f1a..4f6b79b 100644
--- a/src/ustar.h
+++ b/src/ustar.h
@@ -92,6 +92,13 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
uid_t uid, const char *uname, gid_t gid, const char *gname,
uint64_t size, char type, const char *linkname);
+int
+opkg_opk_ustar_get_buffer(struct opkg_opk_ustar *ustar, char **buffer,
+ size_t *size);
+
+int
+opkg_opk_ustar_write_data(struct opkg_opk_ustar *ustar, size_t size);
+
/*
* Frees an archive structure.
* Parameters: