[PATCH 1/2] Add strbuf_cmp.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 strbuf.c |   12 ++++++++++++
 strbuf.h |    1 +
 2 files changed, 13 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)
 {
diff --git a/strbuf.h b/strbuf.h
index 567e2d1..2b5b7c1 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -75,6 +75,7 @@ extern void strbuf_grow(struct strbuf *, size_t);
 
 /*----- 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) {
-- 
1.5.3.2.1067.g96579

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux