blob: 4fe8ccf47ef553c03067a4ad7aea9fd9cb065e22 (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* 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_git_userbuf_h__
#define INCLUDE_git_userbuf_h__
#include "common.h"
/**
* @file git2/userbuf.h
* @brief Buffer export structure
*
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/** An optional initialization macro for `git_userbuf` objects. */
#define GIT_USERBUF_INIT { NULL, 0, 0 }
/** A constant initialization macro for `git_userbuf` objects. */
#define GIT_USERBUF_CONST(str, len) { (char *)(str), 0, (size_t)(len) }
/**
* A data buffer for exporting data from libgit2.
*
* Sometimes libgit2 wants to return an allocated data buffer to the
* caller and have the caller take responsibility for freeing that memory.
* This structure should be freed with `git_userbuf_dispose` when you
* have finished with it.
*/
typedef struct {
/**
* The buffer's contents. This is a NUL terminated C string.
*/
char *ptr;
/**
* This is the allocated size of the allocated buffer. For
* buffers returned to you from libgit2, you should not
* modify this value. For any buffer that you pass to
* libgit2, this remain 0.
*/
size_t asize;
/**
* The size (in bytes) of the data in the buffer, not including
* the NUL terminating character.
*/
size_t size;
} git_userbuf;
/**
* Places the given data in the buffer. This is necessary for some
* callback functions that take user data. If there is already data in
* the buffer, you should call `git_userbuf_dispose` before setting the
* buffer data.
*
* @param buf The buffer to place data into
* @param ptr The data to place in the buffer
* @param len The length of the data in bytes
*/
GIT_EXTERN(int) git_userbuf_set(git_userbuf *buf, const char *ptr, size_t len);
/**
* Free the memory referred to by the git_userbuf.
*
* @param buf The buffer to deallocate
*/
GIT_EXTERN(void) git_userbuf_dispose(git_userbuf *buf);
GIT_END_DECL
/** @} */
#endif
|