diff options
author | Pierre Habouzit <madcoder@debian.org> | 2007-09-24 11:25:03 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-09-26 02:27:05 -0700 |
commit | 45f66f64636350b67eaf6832b0c424592be6ddda (patch) | |
tree | b3299f8c707a2600d2465010c3dfea6f47a3926e | |
parent | strbuf_setlen(): do not barf on setting length of an empty buffer to 0 (diff) | |
download | tgif-45f66f64636350b67eaf6832b0c424592be6ddda.tar.xz |
Add strbuf_cmp.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | strbuf.c | 12 | ||||
-rw-r--r-- | strbuf.h | 1 |
2 files changed, 13 insertions, 0 deletions
@@ -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) { @@ -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) { |