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)
{
sb->buf[sb->len] = '\0';
return 0;
}
+
+int strbuf_read_file(struct strbuf *sb, const char *path)
+{
+ int fd, len;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -1;
+ len = strbuf_read(sb, fd, 0);
+ close(fd);
+ if (len < 0)
+ return -1;
+
+ return len;
+}