diff options
-rw-r--r-- | src/opk.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -398,9 +398,9 @@ _opkg_opk_opk_read_data(struct opkg_opk_opk *opk) char *buffer; size_t size; long int size_len_max; - char fmt[28]; - /* "%c%s %-32s/%-32s %11d %s %s" */ - size_t len; + char fmt[26]; + /* "%c%s %-32s/%-32s %11d %s " */ + int len; char mode[10]; char mtime[20]; @@ -502,7 +502,7 @@ _opkg_opk_opk_read_data(struct opkg_opk_opk *opk) } ret = OPKG_OPK_OK; size_len_max = lrint(ceil(log10(size_max))); - snprintf(fmt, sizeof(fmt), "%%c%%s %%-%zus/%%-%zus %%%lid %%s %%s", + snprintf(fmt, sizeof(fmt), "%%c%%s %%-%zus/%%-%zus %%%lid %%s ", uname_len_max, gname_len_max, size_len_max); len = 34 + uname_len_max + gname_len_max + size_len_max; for (member = head; member != NULL;) { @@ -525,11 +525,24 @@ _opkg_opk_opk_read_data(struct opkg_opk_opk *opk) #pragma GCC diagnostic ignored "-Wformat-nonliteral" if (printf(fmt, member->type, mode, member->uname, member->gname, - member->size, mtime, member->name) != - (int) (len + strlen(member->name))) { + member->size, mtime) != len) { ret = OPKG_OPK_ERROR; } #pragma GCC diagnostic pop + /* Print name, ensuring it begins with "/". */ + if (member->name[0] == '.' && member->name[1] == '/') { + if (fputs(member->name + 1, stdout) == EOF) { + ret = OPKG_OPK_ERROR; + } + } else { + if (member->name[0] != '/' && putchar('/') == EOF) { + ret = OPKG_OPK_ERROR; + } + if (fputs(member->name, stdout) == EOF) { + ret = OPKG_OPK_ERROR; + } + } + /* Print link name, if any. */ if (member->type == 'l' && printf(" -> %s", member->linkname) != (int) (strlen(member->linkname) + 4)) { ret = OPKG_OPK_ERROR; |