summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/opk.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/opk.c b/src/opk.c
index cd92bd6..f32b0a8 100644
--- a/src/opk.c
+++ b/src/opk.c
@@ -187,7 +187,11 @@ opkg_opk_opk_read_control(struct opkg_opk_opk *opk,
while ((ret_read = opkg_opk_ustar_read(opk->inner_ustar,
&buffer, &size)) == OPKG_OPK_OK)
{
- fwrite(buffer, 1, size, stdout);
+ if (fwrite(buffer, 1, size, stdout) != size) {
+ fputs("Error: Failed to print control file\n",
+ stderr);
+ return OPKG_OPK_ERROR;
+ }
}
if (ret_read == OPKG_OPK_ERROR) {
fputs("Error: Failed to read control file\n", stderr);
@@ -218,8 +222,10 @@ opkg_opk_opk_list_members(struct opkg_opk_opk *opk)
size_t gname_len;
size_t gname_len_max;
uint64_t size_max;
+ long int size_len_max;
char fmt[29];
/* "%c%s %-32s/%-32s %11d %s %s\n" */
+ size_t len;
char mode[10];
char mtime[20];
@@ -259,8 +265,11 @@ opkg_opk_opk_list_members(struct opkg_opk_opk *opk)
tail->next = NULL;
/* Print and free members. */
+ ret = OPKG_OPK_OK;
+ size_len_max = lrint(ceil(log10(size_max)));
snprintf(fmt, sizeof(fmt), "%%c%%s %%-%zus/%%-%zus %%%lid %%s %%s\n",
- uname_len, gname_len, lrint(ceil(log10(size_max))));
+ uname_len, gname_len, size_len_max);
+ len = 35 + uname_len + gname_len + size_len_max;
for (member = head; member != NULL;) {
if (member->mode & 00400) mode[0] = 'r'; else mode[0] = '-';
if (member->mode & 00200) mode[1] = 'w'; else mode[1] = '-';
@@ -277,10 +286,12 @@ opkg_opk_opk_list_members(struct opkg_opk_opk *opk)
mode[9] = '\0';
strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S",
localtime(&member->mtime));
- printf(fmt,
- member->type, mode,
+ if (printf(fmt, member->type, mode,
member->uname, member->gname,
- member->size, mtime, member->name);
+ member->size, mtime, member->name) !=
+ (int) (len + strlen(member->name))) {
+ ret = OPKG_OPK_ERROR;
+ }
head = member;
member = member->next;
free(head);
@@ -288,7 +299,7 @@ opkg_opk_opk_list_members(struct opkg_opk_opk *opk)
opk->previously_printed = 1;
- return OPKG_OPK_OK;
+ return ret;
}
void