Skip to content

Commit

Permalink
Add strbuf_cmp.
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Pierre Habouzit authored and Junio C Hamano committed Sep 26, 2007
1 parent a8f3e22 commit 45f66f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 45f66f6

Please sign in to comment.