39 #define _BUF_ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
40 #define BUF_ALIGN(s) _BUF_ALIGN((s), sizeof(double))
67 assert(!(
sizeof(
double) & (
sizeof(
double) - 1)));
74 (*buf)->list = (*buf)->last = 0;
86 #if defined(_DEBUG) && !defined(NDEBUG)
93 && !
buf->size == !(
buf->list ||
buf->last));
95 for (
size = 0, chunk =
buf->list; chunk; chunk = chunk->
next) {
104 return buf ?
buf->size : 0;
122 alloc_size = ((data_size + unit_size - 1) / unit_size) * unit_size;
124 assert(!data_size == !alloc_size);
133 chunk->
extent = alloc_size;
163 chunk->
extent = alloc_size;
166 (*buf)->last->next = chunk;
168 (*buf)->list = chunk;
169 (*buf)->last = chunk;
202 chunk->
next = (*buf)->list;
206 chunk->
extent = alloc_size;
210 (*buf)->last = chunk;
212 (*buf)->list = chunk;
240 assert(!(*buf)->list == !tail && !(*buf)->
size == !tail);
257 memcpy(
next->data, (
const char*) src + pending,
size);
274 void* dst = tail->
data + tail->
size;
277 tail->
size += pending;
279 (*buf)->size += pending +
size;
280 assert((*buf)->size && (*buf)->list && (*buf)->last);
311 memcpy(
next->data, (
const char*) src +
size, skip);
312 (*buf)->size += skip;
330 (*buf)->size +=
size;
331 assert((*buf)->size && (*buf)->list && (*buf)->last);
338 size_t (*callback)(
void*,
const void*,
size_t),
346 && !
buf->size == !(
buf->list ||
buf->last)));
354 todo =
buf->size - pos;
361 if (pos + (todo = chunk->
size - chunk->
skip) <
buf->size) {
362 for (chunk =
buf->list; chunk; chunk = chunk->
next) {
371 pos -=
buf->size - todo;
374 for (todo =
size; todo && chunk; chunk = chunk->
next, pos = 0) {
375 size_t skip = chunk->
skip + pos;
376 size_t peek = chunk->
size - skip;
381 skip = callback(cbdata, (
const char*) chunk->
data + skip, peek);
395 char** dst = (
char**) cbdata;
419 && !
buf->size == !(
buf->list ||
buf->last)));
424 else if (!
buf || !
buf->size)
436 size_t avail =
head->size -
head->skip;
452 }
while (todo &&
buf->list);
455 && !
buf->size == !(
buf->list ||
buf->last));
479 if (!src || !src->
size)
485 assert(!(*dst)->list == !(*dst)->last
486 && !(*dst)->size == !((*dst)->list || (*dst)->last));
488 (*dst)->last->next = src->
list;
490 (*dst)->list = src->
list;
491 (*dst)->last = src->
last;
495 assert((*dst)->size && (*dst)->list && (*dst)->last);
static const int chunk_size
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
int BUF_Write(BUF *buf, const void *src, size_t size)
int BUF_Append(BUF *buf, const void *data, size_t size)
int BUF_Prepend(BUF *buf, const void *data, size_t size)
size_t BUF_PeekAt(BUF buf, size_t pos, void *dst, size_t size)
size_t BUF_SetChunkSize(BUF *buf, size_t chunk_size)
int BUF_PrependEx(BUF *buf, void *base, size_t alloc_size, void *data, size_t size)
int BUF_Pushback(BUF *buf, const void *src, size_t size)
int BUF_AppendEx(BUF *buf, void *base, size_t alloc_size, void *data, size_t size)
size_t BUF_Read(BUF buf, void *dst, size_t size)
int BUF_Splice(BUF *dst, BUF src)
size_t BUF_Peek(BUF buf, void *dst, size_t size)
void BUF_Destroy(BUF buf)
const struct ncbi::grid::netcache::search::fields::SIZE size
static size_t x_BUF_MemcpyCB(void *cbdata, const void *data, size_t size)
struct SBufChunkTag SBufChunk
static SBufChunk * s_BUF_AllocChunk(size_t data_size, size_t unit_size)
size_t BUF_PeekAtCB(BUF buf, size_t pos, size_t(*callback)(void *, const void *, size_t), void *cbdata, size_t size)
#define BUF_DEF_CHUNK_SIZE
struct SBufChunkTag * next