X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fcreate.c;h=42c82fffe71d2a7b9716cf42ca6e31f7506f965f;hb=2c3d0a2dcd36e1ebf6d8a71e4deeaa53a899802f;hp=81066b4dcfac4805e4147a8fafcac814ddc283e4;hpb=14b158325624a6e42e8bf4f7169c7a55f0afb6f9;p=chaz%2Ftar diff --git a/src/create.c b/src/create.c index 81066b4..42c82ff 100644 --- a/src/create.c +++ b/src/create.c @@ -114,25 +114,38 @@ to_chars (int negative, uintmax_t value, size_t valsize, { uintmax_t v = negative ? -value : value; + /* Generate the POSIX octal representation if the number fits. */ if (! negative && v <= MAX_VAL_WITH_DIGITS (size - 1, LG_8)) { where[size - 1] = '\0'; to_base (v, LG_8, base_8_digits, where, size - 1); } + + /* Otherwise, generate the GNU base-64 representation if we are + generating an old or new GNU format and if the number fits. */ else if (v <= MAX_VAL_WITH_DIGITS (size - 1, LG_64) - && archive_format == GNU_FORMAT) + && (archive_format == GNU_FORMAT + || archive_format == OLDGNU_FORMAT)) { where[0] = negative ? '-' : '+'; to_base (v, LG_64, base_64_digits, where + 1, size - 1); } - else if (negative - && archive_format != GNU_FORMAT - && valsize * CHAR_BIT <= (size - 1) * LG_8) + + /* Otherwise, if the number is negative, and if it would not cause + ambiguity on this host by confusing positive with negative + values, then generate the POSIX octal representation of the value + modulo 2**(field bits). The resulting tar file is + machine-dependent, since it depends on the host word size. Yuck! + But this is the traditional behavior. */ + else if (negative && valsize * CHAR_BIT <= (size - 1) * LG_8) { where[size - 1] = '\0'; to_base (value & MAX_VAL_WITH_DIGITS (valsize * CHAR_BIT, 1), LG_8, base_8_digits, where, size - 1); } + + /* Otherwise, output a substitute value if possible (with a + warning), and an error message if not. */ else { uintmax_t maxval = (archive_format == GNU_FORMAT @@ -298,7 +311,7 @@ clear_buffer (char *buffer) } /*-------------------------------------------------------------------------. -| Write the EOT block(s). We actually zero at least one block, through | +| Write the EOT block(s). We zero at least two blocks, through | | the end of the record. Old tar, as previous versions of GNU tar, writes | | garbage after two zeroed blocks. | `-------------------------------------------------------------------------*/ @@ -307,14 +320,11 @@ void write_eot (void) { union block *pointer = find_next_block (); - - if (pointer) - { - size_t space = available_space_after (pointer); - - memset (pointer->buffer, 0, space); - set_next_block_after (pointer); - } + memset (pointer->buffer, 0, BLOCKSIZE); + set_next_block_after (pointer); + pointer = find_next_block (); + memset (pointer->buffer, 0, available_space_after (pointer)); + set_next_block_after (pointer); } /*-----------------------------------------------------.