MCPcopy Create free account
hub / github.com/git/git / strbuf_append_ext_header

Function strbuf_append_ext_header

archive-tar.c:157–177  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

155 * string and appends it to a struct strbuf.
156 */
157static 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.

Callers 3

write_tar_entryFunction · 0.85

Calls 4

strbuf_growFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addchFunction · 0.85

Tested by

no test coverage detected