Code

Sync with maint
[git.git] / strbuf.c
index 60e5e598dd4e49e8b2fd37b0bbb5040639b4411d..ff0b96b4162bd92162a7eb05eee5be7a5ec2b6ba 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -398,6 +398,20 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
        return len;
 }
 
+void strbuf_add_lines(struct strbuf *out, const char *prefix,
+                     const char *buf, size_t size)
+{
+       while (size) {
+               const char *next = memchr(buf, '\n', size);
+               next = next ? (next + 1) : (buf + size);
+               strbuf_addstr(out, prefix);
+               strbuf_add(out, buf, next - buf);
+               size -= next - buf;
+               buf = next;
+       }
+       strbuf_complete_line(out);
+}
+
 static int is_rfc3986_reserved(char ch)
 {
        switch (ch) {