* pax extended header records have the format "%u %s=%s\n". %u contains * the size of the whole string (including the %u), the first %s is the * keyword, the second one is the value. This function constructs such a * string and appends it to a struct strbuf. */
| 155 | * string and appends it to a struct strbuf. |
| 156 | */ |
| 157 | static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, |
| 158 | const char *value, size_t valuelen) |
| 159 | { |
| 160 | size_t orig_len = sb->len; |
| 161 | size_t len, tmp; |
| 162 | |
| 163 | /* "%u %s=%s\n" */ |
| 164 | len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1; |
| 165 | for (tmp = 1; len / 10 >= tmp; tmp *= 10) |
| 166 | len++; |
| 167 | |
| 168 | strbuf_grow(sb, len); |
| 169 | strbuf_addf(sb, "%"PRIuMAX" %s=", (uintmax_t)len, keyword); |
| 170 | strbuf_add(sb, value, valuelen); |
| 171 | strbuf_addch(sb, '\n'); |
| 172 | |
| 173 | if (len != sb->len - orig_len) |
| 174 | BUG("pax extended header length miscalculated as %"PRIuMAX |
| 175 | ", should be %"PRIuMAX, |
| 176 | (uintmax_t)len, (uintmax_t)(sb->len - orig_len)); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Like strbuf_append_ext_header, but for numeric values. |
no test coverage detected