X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=inline;f=src%2Fxheader.c;h=62fbf5db32a569cb3f6ae8504def61527f7f528b;hb=a5bafe7962470f7d888d34b899ec6ff50855d050;hp=b8b85819b100a5001a6337da8068357effadef66;hpb=b8754a37c740d7771637a0ef8f8d7c0683315d5d;p=chaz%2Ftar diff --git a/src/xheader.c b/src/xheader.c index b8b8581..62fbf5d 100644 --- a/src/xheader.c +++ b/src/xheader.c @@ -28,6 +28,8 @@ #define obstack_chunk_free free #include +#include + bool xheader_protected_pattern_p (const char *pattern); bool xheader_protected_keyword_p (const char *keyword); @@ -191,6 +193,26 @@ xheader_set_option (char *string) } } +static void +to_decimal (uintmax_t value, char *where, size_t size) +{ + size_t i = 0, j; + + where[i++] = 0; + do + { + where[i++] = '0' + value % 10; + value /= 10; + } + while (i < size && value); + for (j = 0, i--; j < i; j++, i--) + { + char c = where[j]; + where[j] = where[i]; + where[i] = c; + } +} + /* string Includes: Replaced By: %d The directory name of the file, @@ -241,16 +263,14 @@ xheader_format_name (struct tar_stat_info *st, const char *fmt, bool allow_n) break; case 'p': - snprintf (pidbuf, sizeof pidbuf, "%lu", - (unsigned long) getpid ()); + to_decimal (getpid (), pidbuf, sizeof pidbuf); len += strlen (pidbuf) - 1; break; case 'n': if (allow_n) { - snprintf (nbuf, sizeof nbuf, "%lu", - (unsigned long) global_header_count + 1); + to_decimal (global_header_count + 1, pidbuf, sizeof pidbuf); len += strlen (nbuf) - 1; } break; @@ -574,7 +594,6 @@ void xheader_store (char const *keyword, struct tar_stat_info const *st, void *data) { struct xhdr_tab const *t; - char *value; if (extended_header.buffer) return; @@ -881,7 +900,7 @@ size_decoder (struct tar_stat_info *st, char const *arg) { uintmax_t u; if (xstrtoumax (arg, NULL, 10, &u, "") == LONGINT_OK) - st->stat.st_size = u; + st->archive_file_size = st->stat.st_size = u; } static void @@ -924,7 +943,7 @@ sparse_size_decoder (struct tar_stat_info *st, char const *arg) { uintmax_t u; if (xstrtoumax (arg, NULL, 10, &u, "") == LONGINT_OK) - st->archive_file_size = u; + st->stat.st_size = u; } static void @@ -978,7 +997,7 @@ sparse_numbytes_decoder (struct tar_stat_info *st, char const *arg) { if (st->sparse_map_avail == st->sparse_map_size) { - size_t newsize = st->sparse_map_size *= 2; + st->sparse_map_size *= 2; st->sparse_map = xrealloc (st->sparse_map, st->sparse_map_size * sizeof st->sparse_map[0]);