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 <john@keeping.me.uk>
This commit is contained in:
John Keeping 2013-04-07 14:03:47 +01:00 committed by Jason A. Donenfeld
부모 fd00d2f9d6
커밋 d2e20e3814
2개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제

2
cgit.h
파일 보기

@ -304,6 +304,8 @@ extern char *ensure_end(const char *str, char c);
extern char *strlpart(char *txt, int maxlen); extern char *strlpart(char *txt, int maxlen);
extern char *strrpart(char *txt, int maxlen); extern char *strrpart(char *txt, int maxlen);
extern void strbuf_ensure_end(struct strbuf *sb, char c);
extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
extern void cgit_free_reflist_inner(struct reflist *list); extern void cgit_free_reflist_inner(struct reflist *list);
extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,

파일 보기

@ -130,6 +130,12 @@ char *ensure_end(const char *str, char c)
return result; 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 *strlpart(char *txt, int maxlen)
{ {
char *result; char *result;