Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/prism/internal/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ void pm_buffer_cleanup(pm_buffer_t *buffer);
/* Append the given amount of space as zeroes to the buffer. */
void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length);

/* Append the given byte to the buffer the given number of times. */
void pm_buffer_append_repeated(pm_buffer_t *buffer, uint8_t value, size_t length);

/* Append a formatted string to the buffer. */
void pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) PRISM_ATTRIBUTE_FORMAT(2, 3);

/* Append a string to the buffer. */
void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length);

/*
* Append a string literal to the buffer, with its length computed at compile
* time. Concatenating with "" means anything other than a string literal fails
* to compile, instead of having its pointer size taken as its length.
*/
#define PM_BUFFER_APPEND_LITERAL(buffer, literal) pm_buffer_append_string((buffer), "" literal, sizeof(literal) - 1)

/* Append a list of bytes to the buffer. */
void pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length);

Expand Down
11 changes: 11 additions & 0 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length) {
}
}

/**
* Append the given byte to the buffer the given number of times.
*/
void
pm_buffer_append_repeated(pm_buffer_t *buffer, uint8_t value, size_t length) {
size_t cursor = buffer->length;
if (pm_buffer_append_length(buffer, length)) {
memset(buffer->value + cursor, value, length);
}
}

/**
* Append a formatted string to the buffer.
*/
Expand Down
Loading
Loading