@@ -38,6 +38,13 @@ extern char git_buf__oom[];
3838/* Use to initialize buffer structure when git_buf is on stack */
3939#define GIT_BUF_INIT { git_buf__initbuf, 0, 0 }
4040
41+ /**
42+ * Static initializer for git_buf from static buffer
43+ */
44+ #ifdef GIT_DEPRECATE_HARD
45+ # define GIT_BUF_INIT_CONST (STR ,LEN ) { (char *)(STR), 0, (size_t)(LEN) }
46+ #endif
47+
4148GIT_INLINE (bool ) git_buf_is_allocated (const git_buf * buf )
4249{
4350 return (buf -> ptr != NULL && buf -> asize > 0 );
@@ -51,6 +58,33 @@ GIT_INLINE(bool) git_buf_is_allocated(const git_buf *buf)
5158 */
5259extern int git_buf_init (git_buf * buf , size_t initial_size );
5360
61+ #ifdef GIT_DEPRECATE_HARD
62+
63+ /**
64+ * Resize the buffer allocation to make more space.
65+ *
66+ * This will attempt to grow the buffer to accommodate the target size.
67+ *
68+ * If the buffer refers to memory that was not allocated by libgit2 (i.e.
69+ * the `asize` field is zero), then `ptr` will be replaced with a newly
70+ * allocated block of data. Be careful so that memory allocated by the
71+ * caller is not lost. As a special variant, if you pass `target_size` as
72+ * 0 and the memory is not allocated by libgit2, this will allocate a new
73+ * buffer of size `size` and copy the external data into it.
74+ *
75+ * Currently, this will never shrink a buffer, only expand it.
76+ *
77+ * If the allocation fails, this will return an error and the buffer will be
78+ * marked as invalid for future operations, invaliding the contents.
79+ *
80+ * @param buffer The buffer to be resized; may or may not be allocated yet
81+ * @param target_size The desired available size
82+ * @return 0 on success, -1 on allocation failure
83+ */
84+ int git_buf_grow (git_buf * buffer , size_t target_size );
85+
86+ #endif
87+
5488/**
5589 * Resize the buffer allocation to make more space.
5690 *
@@ -120,6 +154,11 @@ GIT_INLINE(bool) git_buf_oom(const git_buf *buf)
120154 * return code of these functions and call them in a series then just call
121155 * git_buf_oom at the end.
122156 */
157+
158+ #ifdef GIT_DEPRECATE_HARD
159+ int git_buf_set (git_buf * buffer , const void * data , size_t datalen );
160+ #endif
161+
123162int git_buf_sets (git_buf * buf , const char * string );
124163int git_buf_putc (git_buf * buf , char c );
125164int git_buf_putcn (git_buf * buf , char c , size_t len );
@@ -311,4 +350,24 @@ extern int git_buf_detect_bom(git_buf_bom_t *bom, const git_buf *buf);
311350extern bool git_buf_gather_text_stats (
312351 git_buf_text_stats * stats , const git_buf * buf , bool skip_bom );
313352
353+ #ifdef GIT_DEPRECATE_HARD
354+
355+ /**
356+ * Check quickly if buffer looks like it contains binary data
357+ *
358+ * @param buf Buffer to check
359+ * @return 1 if buffer looks like non-text data
360+ */
361+ int git_buf_is_binary (const git_buf * buf );
362+
363+ /**
364+ * Check quickly if buffer contains a NUL byte
365+ *
366+ * @param buf Buffer to check
367+ * @return 1 if buffer contains a NUL byte
368+ */
369+ int git_buf_contains_nul (const git_buf * buf );
370+
371+ #endif
372+
314373#endif
0 commit comments