summaryrefslogtreecommitdiffstats
path: root/src/ustar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ustar.c')
-rw-r--r--src/ustar.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/ustar.c b/src/ustar.c
index 4805880..f403524 100644
--- a/src/ustar.c
+++ b/src/ustar.c
@@ -25,6 +25,8 @@
#include "gzip.h"
#include "ustar.h"
+#define OPKG_OPK_USTAR_NUM_BASE_ 8
+
struct _opkg_opk_ustar_header {
unsigned char name [100];
unsigned char mode [8];
@@ -70,7 +72,7 @@ static int
_opkg_opk_ustar_next(struct opkg_opk_ustar *ustar,
struct _opkg_opk_ustar_header *header)
{
- static unsigned char record[512];
+ static unsigned char record[OPKG_OPK_USTAR_RECORD_SIZE];
char *size_end;
switch (opkg_opk_gzip_read(ustar->gzip, header)) {
@@ -80,8 +82,8 @@ _opkg_opk_ustar_next(struct opkg_opk_ustar *ustar,
case OPKG_OPK_ERROR:
return OPKG_OPK_ERROR;
}
- memset(record, 0, 512);
- if (memcmp(header, record, 512) == 0) {
+ memset(record, 0, OPKG_OPK_USTAR_RECORD_SIZE);
+ if (memcmp(header, record, OPKG_OPK_USTAR_RECORD_SIZE) == 0) {
return OPKG_OPK_END;
}
if (memcmp(header->magic, "ustar", strlen("ustar")) != 0) {
@@ -89,7 +91,7 @@ _opkg_opk_ustar_next(struct opkg_opk_ustar *ustar,
}
ustar->data_size_remaining = strtol((char *) header->size, &size_end,
- 8);
+ OPKG_OPK_USTAR_NUM_BASE_);
if (*size_end != '\0') {
return OPKG_OPK_ERROR;
}
@@ -111,8 +113,8 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar,
if (record.prefix[0] != '\0') {
sprintf(member->name, "%s/%s", record.prefix, record.name);
} else {
- memcpy(member->name, record.name, 100);
- member->name[100] = '\0';
+ memcpy(member->name, record.name, sizeof(record.name));
+ member->name[sizeof(record.name)] = '\0';
}
while (ustar->data_size_remaining > 0) {
@@ -129,7 +131,7 @@ int
opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member)
{
static struct _opkg_opk_ustar_header record;
- static unsigned char name[257];
+ static unsigned char name[OPKG_OPK_USTAR_NAME_MAX_LEN];
int ret;
for (;;) {
@@ -142,8 +144,8 @@ opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member)
sprintf((char *) name, "%s/%s", record.prefix,
record.name);
} else {
- memcpy(name, record.name, 100);
- name[100] = '\0';
+ memcpy(name, record.name, sizeof(record.name));
+ name[sizeof(record.name)] = '\0';
}
if (strcmp((char *) name, member) == 0) {
@@ -178,11 +180,11 @@ opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char *buffer, size_t *size)
return OPKG_OPK_ERROR;
}
- if (ustar->data_size_remaining >= 512) {
+ if (ustar->data_size_remaining >= OPKG_OPK_USTAR_RECORD_SIZE) {
if (size != NULL) {
- *size = 512;
+ *size = OPKG_OPK_USTAR_RECORD_SIZE;
}
- ustar->data_size_remaining -= 512;
+ ustar->data_size_remaining -= OPKG_OPK_USTAR_RECORD_SIZE;
} else {
if (size != NULL) {
*size = ustar->data_size_remaining;