From: Pierre Habouzit Date: Mon, 24 Sep 2007 09:25:03 +0000 (+0200) Subject: Add strbuf_cmp. X-Git-Tag: v1.5.4-rc0~387^2~9 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=45f66f64636350b67eaf6832b0c424592be6ddda;p=git.git Add strbuf_cmp. Signed-off-by: Junio C Hamano --- diff --git a/strbuf.c b/strbuf.c index dcb725dcd..d5e92ee17 100644 --- a/strbuf.c +++ b/strbuf.c @@ -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) { diff --git a/strbuf.h b/strbuf.h index 3b19de304..fd6838933 100644 --- a/strbuf.h +++ b/strbuf.h @@ -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) {