Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/imh-pyth.../include/git2
File: buffer.h
/*
[0] Fix | Delete
* Copyright (C) the libgit2 contributors. All rights reserved.
[1] Fix | Delete
*
[2] Fix | Delete
* This file is part of libgit2, distributed under the GNU GPL v2 with
[3] Fix | Delete
* a Linking Exception. For full terms see the included COPYING file.
[4] Fix | Delete
*/
[5] Fix | Delete
#ifndef INCLUDE_git_buf_h__
[6] Fix | Delete
#define INCLUDE_git_buf_h__
[7] Fix | Delete
[8] Fix | Delete
#include "common.h"
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* @file git2/buffer.h
[12] Fix | Delete
* @brief Buffer export structure
[13] Fix | Delete
*
[14] Fix | Delete
* @ingroup Git
[15] Fix | Delete
* @{
[16] Fix | Delete
*/
[17] Fix | Delete
GIT_BEGIN_DECL
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* A data buffer for exporting data from libgit2
[21] Fix | Delete
*
[22] Fix | Delete
* Sometimes libgit2 wants to return an allocated data buffer to the
[23] Fix | Delete
* caller and have the caller take responsibility for freeing that memory.
[24] Fix | Delete
* This can be awkward if the caller does not have easy access to the same
[25] Fix | Delete
* allocation functions that libgit2 is using. In those cases, libgit2
[26] Fix | Delete
* will fill in a `git_buf` and the caller can use `git_buf_dispose()` to
[27] Fix | Delete
* release it when they are done.
[28] Fix | Delete
*
[29] Fix | Delete
* A `git_buf` may also be used for the caller to pass in a reference to
[30] Fix | Delete
* a block of memory they hold. In this case, libgit2 will not resize or
[31] Fix | Delete
* free the memory, but will read from it as needed.
[32] Fix | Delete
*
[33] Fix | Delete
* Some APIs may occasionally do something slightly unusual with a buffer,
[34] Fix | Delete
* such as setting `ptr` to a value that was passed in by the user. In
[35] Fix | Delete
* those cases, the behavior will be clearly documented by the API.
[36] Fix | Delete
*/
[37] Fix | Delete
typedef struct {
[38] Fix | Delete
/**
[39] Fix | Delete
* The buffer contents.
[40] Fix | Delete
*
[41] Fix | Delete
* `ptr` points to the start of the allocated memory. If it is NULL,
[42] Fix | Delete
* then the `git_buf` is considered empty and libgit2 will feel free
[43] Fix | Delete
* to overwrite it with new data.
[44] Fix | Delete
*/
[45] Fix | Delete
char *ptr;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* `asize` holds the known total amount of allocated memory if the `ptr`
[49] Fix | Delete
* was allocated by libgit2. It may be larger than `size`. If `ptr`
[50] Fix | Delete
* was not allocated by libgit2 and should not be resized and/or freed,
[51] Fix | Delete
* then `asize` will be set to zero.
[52] Fix | Delete
*/
[53] Fix | Delete
size_t asize;
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* `size` holds the size (in bytes) of the data that is actually used.
[57] Fix | Delete
*/
[58] Fix | Delete
size_t size;
[59] Fix | Delete
} git_buf;
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Static initializer for git_buf from static buffer
[63] Fix | Delete
*/
[64] Fix | Delete
#define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) }
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Free the memory referred to by the git_buf.
[68] Fix | Delete
*
[69] Fix | Delete
* Note that this does not free the `git_buf` itself, just the memory
[70] Fix | Delete
* pointed to by `buffer->ptr`. This will not free the memory if it looks
[71] Fix | Delete
* like it was not allocated internally, but it will clear the buffer back
[72] Fix | Delete
* to the empty state.
[73] Fix | Delete
*
[74] Fix | Delete
* @param buffer The buffer to deallocate
[75] Fix | Delete
*/
[76] Fix | Delete
GIT_EXTERN(void) git_buf_dispose(git_buf *buffer);
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Resize the buffer allocation to make more space.
[80] Fix | Delete
*
[81] Fix | Delete
* This will attempt to grow the buffer to accommodate the target size.
[82] Fix | Delete
*
[83] Fix | Delete
* If the buffer refers to memory that was not allocated by libgit2 (i.e.
[84] Fix | Delete
* the `asize` field is zero), then `ptr` will be replaced with a newly
[85] Fix | Delete
* allocated block of data. Be careful so that memory allocated by the
[86] Fix | Delete
* caller is not lost. As a special variant, if you pass `target_size` as
[87] Fix | Delete
* 0 and the memory is not allocated by libgit2, this will allocate a new
[88] Fix | Delete
* buffer of size `size` and copy the external data into it.
[89] Fix | Delete
*
[90] Fix | Delete
* Currently, this will never shrink a buffer, only expand it.
[91] Fix | Delete
*
[92] Fix | Delete
* If the allocation fails, this will return an error and the buffer will be
[93] Fix | Delete
* marked as invalid for future operations, invaliding the contents.
[94] Fix | Delete
*
[95] Fix | Delete
* @param buffer The buffer to be resized; may or may not be allocated yet
[96] Fix | Delete
* @param target_size The desired available size
[97] Fix | Delete
* @return 0 on success, -1 on allocation failure
[98] Fix | Delete
*/
[99] Fix | Delete
GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size);
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Set buffer to a copy of some raw data.
[103] Fix | Delete
*
[104] Fix | Delete
* @param buffer The buffer to set
[105] Fix | Delete
* @param data The data to copy into the buffer
[106] Fix | Delete
* @param datalen The length of the data to copy into the buffer
[107] Fix | Delete
* @return 0 on success, -1 on allocation failure
[108] Fix | Delete
*/
[109] Fix | Delete
GIT_EXTERN(int) git_buf_set(
[110] Fix | Delete
git_buf *buffer, const void *data, size_t datalen);
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Check quickly if buffer looks like it contains binary data
[114] Fix | Delete
*
[115] Fix | Delete
* @param buf Buffer to check
[116] Fix | Delete
* @return 1 if buffer looks like non-text data
[117] Fix | Delete
*/
[118] Fix | Delete
GIT_EXTERN(int) git_buf_is_binary(const git_buf *buf);
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Check quickly if buffer contains a NUL byte
[122] Fix | Delete
*
[123] Fix | Delete
* @param buf Buffer to check
[124] Fix | Delete
* @return 1 if buffer contains a NUL byte
[125] Fix | Delete
*/
[126] Fix | Delete
GIT_EXTERN(int) git_buf_contains_nul(const git_buf *buf);
[127] Fix | Delete
[128] Fix | Delete
GIT_END_DECL
[129] Fix | Delete
[130] Fix | Delete
/** @} */
[131] Fix | Delete
[132] Fix | Delete
#endif
[133] Fix | Delete
[134] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function