Three buffer families:
XByteBuffer_*: dynamic byte bufferXDataBuffer_*: pointer bufferXRingBuffer_*: circular queue of byte buffers
- Duplicates
nSizebytes and appends a trailing NUL. - Returns allocated buffer or
NULL.
nFastAllocenables geometric growth on reserve.Newallocates the struct and initializes it.Initreturns new reserved size or negative status.
Clear: frees owned storage and resets fields.Free: clears and frees the struct when it was heap-allocated.Reset: keeps allocated storage but sets used length to zero.
Resizereallocates exact capacity.Reserveensures space fornUsed + nSize.- Return resulting size or negative error.
Resize(0)clears buffer and returnsXSTDNON.
- Attach external storage without owning/resizing semantics.
- Return attached used length.
- Transfer ownership into
pBuffer. - Return resulting owned size.
- Append bytes, one byte,
xstring_t, formatted text or another byte buffer. - Return new used length on success.
- Return
XSTDERR/XSTDNONon failure depending on path.
- Inserts bytes at position or appends when
nPosit >= nUsed. - Returns new used length or
XSTDERR.
- Removes bytes in place without shrinking allocation.
- Returns number of removed bytes or
0.
- Removes bytes and then resizes to exact
nUsed + 1. - Returns buffer status.
- Deletes from the front.
- Returns new used length.
Terminatetruncates used length atnPosit.NullTermensures trailing NUL at current end.- Return
XSTDOK/used length orXSTDERR.
- Reads stdin until EOF and appends.
- Returns final used length or
XSTDERR.
- Returns byte at index or
0when out of range.
- Returns
XTRUEwhen buffer exists andnUsed > 0.
- Allocates pointer table of
nSize. - Returns capacity or
XSTDERR.
ClearrunsclearCbfor every slot and resets usage.Destroyalso frees the pointer table.
- Appends pointer.
- Returns appended index on success.
- Returns
-2when reallocation failed after full buffer path, orXSTDERRwhen capacity is already full before growth.
- Replaces pointer at index.
- Returns previous pointer.
- Caveat:
- current bounds condition is loose and should not be trusted blindly.
- Returns pointer at index.
- Returns
NULLwhennIndex >= nUsedornIndex == 0.
- Removes pointer and shifts later items left.
- Returns removed pointer or
NULL.
- Allocates
nSizeinternalxbyte_buffer_tslots. - Returns capacity or
0.
Resetclears/free each slot and resets indices.Destroyalso frees the slot table.
- Internal index maintenance helpers.
Advancedrops the oldest item.
AddDataappends into current back slot when ring is not full.AddDataAdvauto-advances/drops oldest when full.- Return append status from
XByteBuffer_Addor0.
- Returns front slot pointer and size.
- Returns
1on success,0on failure. - Caveat:
- current full-buffer check is inverted; a full ring may be treated as unavailable.
- Copies front slot bytes into caller buffer, clears that slot and advances.
- Returns copied byte count.