Skip to content
Start free evaluation

pdcomm_buffer_create

Function

Copies caller bytes into a new owned buffer.

PdcommStatus pdcomm_buffer_create(const uint8_t *data, size_t length, size_t max_bytes, PdcommBuffer **out)

Declared in: #include <pdcomm.h>

The input is copied; the caller keeps ownership of data.

Parameters

NameDescription
dataBytes to copy. May be NULL when length is 0.
lengthNumber of bytes at data.
max_bytesLargest length the application allows. This is application policy, not a protocol constant.
outReceives the new buffer handle. Set to NULL before any other check, so it is NULL after every failure. Must not overlap data.

Returns

#PDCOMM_OK on success; #PDCOMM_INVALID_ARGUMENT when out is NULL, data is NULL with a nonzero length, or length exceeds PTRDIFF_MAX; #PDCOMM_LIMIT_EXCEEDED when length exceeds max_bytes; #PDCOMM_ALLOCATION_FAILED when memory could not be allocated; #PDCOMM_INTERNAL_ERROR when a panic was contained.

Notes

  • Ownership: release the handle exactly once with pdcomm_buffer_destroy().