summaryrefslogtreecommitdiff
path: root/src/buffer.h
blob: ad3b8930f2f53dcf51e099f5cb6e39c97dce3541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright (C) 2009-2011 the libgit2 contributors
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#ifndef INCLUDE_buffer_h__
#define INCLUDE_buffer_h__

#include "common.h"

typedef struct {
	char *ptr;
	ssize_t asize, size;
} git_buf;

#define GIT_BUF_INIT {NULL, 0, 0}

int git_buf_grow(git_buf *buf, size_t target_size);
int git_buf_oom(const git_buf *buf);
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);

#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)

#endif