]> git.proxmox.com Git - libgit2.git/blob - src/buffer.h
Merge pull request #499 from arrbee/extend-git-buf
[libgit2.git] / src / buffer.h
1 /*
2 * Copyright (C) 2009-2011 the libgit2 contributors
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_buffer_h__
8 #define INCLUDE_buffer_h__
9
10 #include "common.h"
11
12 typedef struct {
13 char *ptr;
14 ssize_t asize, size;
15 } git_buf;
16
17 #define GIT_BUF_INIT {NULL, 0, 0}
18
19 int git_buf_grow(git_buf *buf, size_t target_size);
20 void git_buf_free(git_buf *buf);
21 void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
22
23 /**
24 * Any function that writes to a git_buf can fail due to memory allocation
25 * issues. If one fails, the git_buf will be marked with an OOM error and
26 * further calls to modify the buffer will fail. You just check
27 * git_buf_oom() at the end of your sequence and it will be true if you ran
28 * out of memory at any point with that buffer.
29 */
30 int git_buf_oom(const git_buf *buf);
31
32 void git_buf_set(git_buf *buf, const char *data, size_t len);
33 void git_buf_sets(git_buf *buf, const char *string);
34 void git_buf_putc(git_buf *buf, char c);
35 void git_buf_put(git_buf *buf, const char *data, size_t len);
36 void git_buf_puts(git_buf *buf, const char *string);
37 void git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
38 void git_buf_clear(git_buf *buf);
39 void git_buf_consume(git_buf *buf, const char *end);
40 void git_buf_join_n(git_buf *buf, char separator, int nbuf, ...);
41 void git_buf_join(git_buf *buf, char separator, const char *str_a, const char *str_b);
42
43 const char *git_buf_cstr(git_buf *buf);
44 char *git_buf_take_cstr(git_buf *buf);
45
46 #define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
47
48 #endif