summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-24 09:25:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-09-26 09:27:05 (GMT)
commit45f66f64636350b67eaf6832b0c424592be6ddda (patch)
treeb3299f8c707a2600d2465010c3dfea6f47a3926e /strbuf.c
parenta8f3e2219c237661a30b54fe23d58e055f0b548c (diff)
downloadgit-45f66f64636350b67eaf6832b0c424592be6ddda.zip
git-45f66f64636350b67eaf6832b0c424592be6ddda.tar.gz
git-45f66f64636350b67eaf6832b0c424592be6ddda.tar.bz2
Add strbuf_cmp.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/strbuf.c b/strbuf.c
index dcb725d..d5e92ee 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)
{