@matheusbsbs / matheus-bagliano / commits / 45f66f6463
Fork 0

Add strbuf_cmp.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pierre Habouzit committed Sep 24, 2007 at 11:25 UTC 45f66f64636350b67eaf6832b0c424592be6ddda
2 files changed +13
strbuf.c
+12
@@ -50,6 +50,18 @@ void strbuf_rtrim(struct strbuf *sb)
50 sb->buf[sb->len] = '\0';
51 }
52
53 +int strbuf_cmp(struct strbuf *a, struct strbuf *b)
54 +{
55 + int cmp;
56 + if (a->len < b->len) {
57 + cmp = memcmp(a->buf, b->buf, a->len);
58 + return cmp ? cmp : -1;
59 + } else {
60 + cmp = memcmp(a->buf, b->buf, b->len);
61 + return cmp ? cmp : a->len != b->len;
62 + }
63 +}
64 +
65 void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
66 const void *data, size_t dlen)
67 {
strbuf.h
+1
@@ -78,6 +78,7 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
78
79 /*----- content related -----*/
80 extern void strbuf_rtrim(struct strbuf *);
81 +extern int strbuf_cmp(struct strbuf *, struct strbuf *);
82
83 /*----- add data in your buffer -----*/
84 static inline void strbuf_addch(struct strbuf *sb, int c) {