Table Of Contents

Previous topic

Hash Table

Next topic

Logger

Buffer

A buffer data structure with exponential growth that ensures that it is always null padded.

Summary

s_buffer_new Create a new buffer.
s_buffer_delete Delete a buffer and it’s contents.
s_buffer_append Append a number of bytes to the given buffer.
s_buffer_clear Clear the data in the buffer.
s_buffer_data Get a pointer to the beginning of the data in the buffer.
s_buffer_size Get the size of the data in the buffer.
s_buffer_truncate Truncate the buffer.

Definition

typedef struct s_buffer s_buffer

Opaque definition of the buffer.

It is a buffer with exponential growth, that ensures that it is always null padded.

Create/Delete

s_buffer *s_buffer_new(s_erc *error)

Create a new buffer.

Parameters:
  • error

    Error code.

Return:

Pointer to a new buffer data structure.

void s_buffer_delete(s_buffer *buf, s_erc *error)

Delete a buffer and it’s contents.

Parameters:
  • buf

    The buffer to delete.

  • error

    Error code.

Data Functions

void s_buffer_append(s_buffer *buf, const void *data, size_t size, s_erc *error)

Append a number of bytes to the given buffer.

Parameters:
  • buf

    The buffer to append to.

  • data

    The data to append to the buffer.

  • size

    The size of the data in bytes.

  • error

    Error code.

void s_buffer_clear(s_buffer *buf, s_erc *error)

Clear the data in the buffer.

Parameters:
  • buf

    The buffer to clear.

  • error

    Error code.

const uchar *s_buffer_data(const s_buffer *buf, s_erc *error)

Get a pointer to the beginning of the data in the buffer.

Parameters:
  • buf

    The buffer to get the data of.

  • error

    Error code.

Return:

Pointer to the data in the buffer.

Miscellaneous

size_t s_buffer_size(const s_buffer *buf, s_erc *error)

Get the size of the data in the buffer.

Parameters:
  • buf

    The buffer to get the size of.

  • error

    Error code.

Return:

Size of data in buffer (bytes).

void s_buffer_truncate(s_buffer *buf, size_t len, s_erc *error)

Truncate the buffer.

Parameters:
  • buf

    The buffer to truncate.

  • len

    The number of bytes to truncate.

  • error

    Error code.