1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

Add strbuf_cmp.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Pierre Habouzit 2007-09-24 11:25:03 +02:00 committed by Junio C Hamano
parent a8f3e2219c
commit 45f66f6463
2 changed files with 13 additions and 0 deletions

View file

@ -50,6 +50,18 @@ void strbuf_rtrim(struct strbuf *sb)
sb->buf[sb->len] = '\0';
}
int strbuf_cmp(struct strbuf *a, struct strbuf *b)
{
int cmp;
if (a->len < b->len) {
cmp = memcmp(a->buf, b->buf, a->len);
return cmp ? cmp : -1;
} else {
cmp = memcmp(a->buf, b->buf, b->len);
return cmp ? cmp : a->len != b->len;
}
}
void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
const void *data, size_t dlen)
{

View file

@ -78,6 +78,7 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
/*----- content related -----*/
extern void strbuf_rtrim(struct strbuf *);
extern int strbuf_cmp(struct strbuf *, struct strbuf *);
/*----- add data in your buffer -----*/
static inline void strbuf_addch(struct strbuf *sb, int c) {