From d2e20e38141c882e46eaa77f172fc2ae37a19d3b Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 7 Apr 2013 14:03:47 +0100 Subject: shared.c: add strbuf_ensure_end This is a small helper so that we can easily ensure that a strbuf ends with the specified character. Signed-off-by: John Keeping --- shared.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'shared.c') diff --git a/shared.c b/shared.c index 1fa9c99..10be355 100644 --- a/shared.c +++ b/shared.c @@ -130,6 +130,12 @@ char *ensure_end(const char *str, char c) return result; } +void strbuf_ensure_end(struct strbuf *sb, char c) +{ + if (!sb->len || sb->buf[sb->len - 1] != c) + strbuf_addch(sb, c); +} + char *strlpart(char *txt, int maxlen) { char *result; -- cgit v1.2.3-70-g09d2