[PATCH v2 04/22] html.c: add fmtalloc helper
John Keeping
john at keeping.me.uk
Sun Apr 7 16:26:33 CEST 2013
Signed-off-by: John Keeping <john at keeping.me.uk>
---
cgit.h | 3 +++
html.c | 12 ++++++++++++
2 files changed, 15 insertions(+)
diff --git a/cgit.h b/cgit.h
index 7581cc1..7619cbb 100644
--- a/cgit.h
+++ b/cgit.h
@@ -327,6 +327,9 @@ extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
__attribute__((format (printf,1,2)))
extern char *fmt(const char *format,...);
+__attribute__((format (printf,1,2)))
+extern char *fmtalloc(const char *format,...);
+
extern struct commitinfo *cgit_parse_commit(struct commit *commit);
extern struct taginfo *cgit_parse_tag(struct tag *tag);
extern void cgit_parse_url(const char *url);
diff --git a/html.c b/html.c
index 8c45ba6..c0cb4b7 100644
--- a/html.c
+++ b/html.c
@@ -63,6 +63,18 @@ char *fmt(const char *format, ...)
return buf[bufidx];
}
+char *fmtalloc(const char *format, ...)
+{
+ struct strbuf sb = STRBUF_INIT;
+ va_list args;
+
+ va_start(args, format);
+ strbuf_vaddf(&sb, format, args);
+ va_end(args);
+
+ return strbuf_detach(&sb, NULL);
+}
+
void html_raw(const char *data, size_t size)
{
if (write(htmlfd, data, size) != size)
--
1.8.2.692.g17a9715
More information about the CGit
mailing list