22 typedef struct buf_t buf_t;
26 size_t buf_get_default_chunk_size(
const buf_t *buf);
28 #define buf_free(b) FREE_AND_NULL(buf_t, buf_free_, (b))
33 #define BUF_MAX_LEN (INT_MAX - 1)
40 size_t buf_get_total_allocation(
void);
42 int buf_add(buf_t *buf,
const char *
string,
size_t string_len);
48 int buf_move_to_buf(buf_t *buf_out, buf_t *buf_in,
size_t *buf_flushlen);
50 void buf_peek(const buf_t *buf,
char *
string,
size_t string_len);
52 int buf_get_bytes(buf_t *buf,
char *
string,
size_t string_len);
53 int buf_get_line(buf_t *buf,
char *data_out,
size_t *data_len);
55 #define PEEK_BUF_STARTSWITH_MAX 16
65 const char **head_out,
size_t *len_out);
68 #ifdef BUFFERS_PRIVATE
70 buf_t *buf_new_with_data(
const char *cp,
size_t sz);
74 #define DEBUG_CHUNK_ALLOC
76 typedef struct chunk_t {
80 #ifdef DEBUG_CHUNK_ALLOC
84 uint32_t inserted_time;
85 char mem[FLEXIBLE_ARRAY_MEMBER];
90 #define BUFFER_MAGIC 0xB0FFF312u
96 size_t default_chunk_size;
105 #define MIN_READ_LEN 8
110 CHUNK_REMAINING_CAPACITY(
const chunk_t *chunk)
112 return (chunk->mem + chunk->memlen) - (chunk->data + chunk->datalen);
118 CHUNK_WRITE_PTR(chunk_t *chunk)
120 return chunk->data + chunk->datalen;
chunk_t * buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
size_t buf_preferred_chunk_size(size_t target)
void buf_add_printf(buf_t *buf, const char *format,...)
size_t buf_move_all(buf_t *buf_out, buf_t *buf_in)
void buf_clear(buf_t *buf)
buf_t * buf_new_with_capacity(size_t size)
int buf_add(buf_t *buf, const char *string, size_t string_len)
void buf_drain(buf_t *buf, size_t n)
size_t buf_allocation(const buf_t *buf)
int buf_find_string_offset(const buf_t *buf, const char *s, size_t n)
size_t buf_datalen(const buf_t *buf)
buf_t * buf_copy(const buf_t *buf)
uint32_t buf_get_oldest_chunk_timestamp(const buf_t *buf, uint32_t now)
int buf_peek_startswith(const buf_t *buf, const char *cmd)
void buf_assert_ok(buf_t *buf)
int buf_get_line(buf_t *buf, char *data_out, size_t *data_len)
size_t buf_slack(const buf_t *buf)
void buf_add_vprintf(buf_t *buf, const char *format, va_list args)
void buf_peek(const buf_t *buf, char *string, size_t string_len)
int buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
void buf_free_(buf_t *buf)
void buf_add_string(buf_t *buf, const char *string)
int buf_set_to_copy(buf_t **output, const buf_t *input)
int buf_get_bytes(buf_t *buf, char *string, size_t string_len)
char * buf_extract(buf_t *buf, size_t *sz_out)
void buf_pullup(buf_t *buf, size_t bytes, const char **head_out, size_t *len_out)
Utility macros to handle different features and behavior in different compilers.
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Integer definitions used throughout Tor.