CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <cx/cx.h>
4
5CX_C_BEGIN
6
9
27
33 union {
34 void* _is_buffer;
35 size_t sz;
36 };
37 size_t len;
38 uint8 data[];
39};
40
48typedef struct BufIov {
49 void* data;
50 size_t len;
52
58_Ret_notnull_ Buffer bufCreate(size_t size);
59
68_Must_inspect_result_ _Ret_maybenull_ Buffer bufTryCreate(size_t size);
69
78_At_(*buf, _Pre_maybenull_ _Post_notnull_) void bufResize(_Inout_ Buffer* buf, size_t newsize);
79
89_At_(*buf, _Pre_maybenull_) bool bufTryResize(_Inout_ Buffer* buf, size_t newsize);
90
97_Pure _meta_inline size_t bufLen(_In_opt_ Buffer buf)
98{
99 return buf ? buf->len : 0;
100}
101
110_meta_inline void bufClear(_Inout_opt_ Buffer buf)
111{
112 if (buf)
113 buf->len = 0;
114}
115
133_At_(*buf, _Pre_maybenull_ _Post_notnull_) _Ret_notnull_ uint8* bufReserve(_Inout_ Buffer* buf,
134 size_t len);
135
151_At_(*buf, _Pre_maybenull_ _Post_notnull_) void bufAppendBytes(_Inout_ Buffer* buf,
152 _In_reads_bytes_opt_(len)
153 const void* data,
154 size_t len);
155
168_At_(*buf, _Pre_maybenull_ _Post_notnull_) void bufAppend(_Inout_ Buffer* buf, _In_opt_ Buffer src);
169
187_At_(*buf, _Pre_maybenull_) _At_(*src, _Pre_maybenull_ _Post_null_) void
188bufAppendC(_Inout_ Buffer* buf, _Inout_ Buffer* src);
189
196_At_(*buf, _Pre_maybenull_ _Post_null_) void bufDestroy(_Inout_ Buffer* buf);
197
199
200CX_C_END
void bufAppendC(Buffer *buf, Buffer *src)
void bufAppendBytes(Buffer *buf, _In_reads_bytes_opt_(len) const void *data, size_t len)
void bufClear(Buffer buf)
Definition buffer.h:110
bool bufTryResize(Buffer *buf, size_t newsize)
Buffer bufTryCreate(size_t size)
void bufDestroy(Buffer *buf)
size_t bufLen(Buffer buf)
Definition buffer.h:97
uint8 * bufReserve(Buffer *buf, size_t len)
void bufAppend(Buffer *buf, Buffer src)
Buffer bufCreate(size_t size)
void bufResize(Buffer *buf, size_t newsize)
size_t len
Number of valid bytes in this region.
Definition buffer.h:50
void * data
Pointer to the start of this region.
Definition buffer.h:49
size_t sz
Total allocated size of buffer in bytes.
Definition buffer.h:35
size_t len
Length of valid data currently in buffer.
Definition buffer.h:37
uint8 data[]
Buffer data (flexible array member)
Definition buffer.h:38