-
-/*------------------------------------------------------------------------.
-| Convert VALUE into a size-SIZE field at WHERE, including a |
-| trailing space. For example, 3 for SIZE means two digits and a space. |
-| |
-| We assume the trailing NUL is already there and don't fill it in. This |
-| fact is used by start_header and finish_header, so don't change it! |
-`------------------------------------------------------------------------*/
-
-/* This should be equivalent to: sprintf (WHERE, "%*lo ", SIZE - 1, VALUE);
- except that we don't assume VALUE fits in an unsigned long, and
- except that sprintf fills in the trailing NUL and we don't. */
+/* Base 64 digits; see Internet RFC 2045 Table 1. */
+char const base_64_digits[64] =
+{
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
+};
+#define base_8_digits (base_64_digits + 26 * 2)
+
+/* The maximum uintmax_t value that can be represented with DIGITS digits,
+ assuming that each digit is BITS_PER_DIGIT wide. */
+#define MAX_VAL_WITH_DIGITS(digits, bits_per_digit) \
+ ((digits) * (bits_per_digit) < sizeof (uintmax_t) * CHAR_BIT \
+ ? ((uintmax_t) 1 << ((digits) * (bits_per_digit))) - 1 \
+ : (uintmax_t) -1)
+
+/* Convert VALUE to a representation suitable for tar headers,
+ using base 1 << BITS_PER_DIGIT.
+ Use the digits in DIGIT_CHAR[0] ... DIGIT_CHAR[base - 1].
+ Output to buffer WHERE with size SIZE.
+ The result is undefined if SIZE is 0 or if VALUE is too large to fit. */