diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-19 08:12:52 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-19 08:31:24 (EDT) |
commit | 33c4702cd0faa018a37b7dc73406fe2bb7e1b252 (patch) | |
tree | 349c2a1109fbeafceff0b92610355037a24b019c | |
parent | 532ad63744cd9c5e657599be0b16652bcc15fe5c (diff) |
opk: Return error if unable to write to stdout
-rw-r--r-- | src/opk.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -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 |