Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-11-28 09:47:58 +0400
committerRussell Belfer <arrbee@arrbee.com>2011-11-28 09:56:44 +0400
commit8c74d22ebfae33323b5561d9bd988f272ff61a01 (patch)
tree29d4bfd7f0f13c141e37c1aeb8ab8cfaa41b85cf /src/buffer.h
parent880b6f0c22153db164ecb3a18c362ba8337365d3 (diff)
Extend git_buf with new utility functions and unit tests.
Add new functions to git_buf for: * initializing a buffer from a string * joining one or more strings onto a buffer with separators * swapping two buffers in place * extracting data from a git_buf (leaving it empty) Also, make git_buf_free leave a git_buf back in its initted state, and slightly tweak buffer allocation sizes and thresholds. Finally, port unit tests to clay and extend with lots of new tests for the various git_buf functions.
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/buffer.h b/src/buffer.h
index ad3b8930f..baa8f4f4d 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -17,15 +17,30 @@ typedef struct {
#define GIT_BUF_INIT {NULL, 0, 0}
int git_buf_grow(git_buf *buf, size_t target_size);
+void git_buf_free(git_buf *buf);
+void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
+
+/**
+ * Any function that writes to a git_buf can fail due to memory allocation
+ * issues. If one fails, the git_buf will be marked with an OOM error and
+ * further calls to modify the buffer will fail. You just check
+ * git_buf_oom() at the end of your sequence and it will be true if you ran
+ * out of memory at any point with that buffer.
+ */
int git_buf_oom(const git_buf *buf);
+
+void git_buf_set(git_buf *buf, const char *data, size_t len);
+void git_buf_sets(git_buf *buf, const char *string);
void git_buf_putc(git_buf *buf, char c);
void git_buf_put(git_buf *buf, const char *data, size_t len);
void git_buf_puts(git_buf *buf, const char *string);
void git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
-const char *git_buf_cstr(git_buf *buf);
-void git_buf_free(git_buf *buf);
void git_buf_clear(git_buf *buf);
void git_buf_consume(git_buf *buf, const char *end);
+void git_buf_join(git_buf *buf, char separator, int nbuf, ...);
+
+const char *git_buf_cstr(git_buf *buf);
+char *git_buf_take_cstr(git_buf *buf);
#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)