damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 623b8603c2793703a0be63a733a21238af0b3cd3
parent d8b083010dd3fa707c94617fb4089838e4f42ee5
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 27 Dec 2023 12:41:59 -0800

nostrdb/cursor: add align function

handy function for padding buffers to some byte alignment

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mnostrdb/src/cursor.h | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/nostrdb/src/cursor.h b/nostrdb/src/cursor.h @@ -714,4 +714,19 @@ static void consume_whitespace_or_punctuation(struct cursor *cur) } } +// pad cursor buffer to n-byte alignment +static inline int cursor_align(struct cursor *cur, int bytes) { + size_t size = cur->p - cur->start; + int pad; + + // pad to n-byte alignment + pad = ((size + (bytes-1)) & ~(bytes-1)) - size; + + if (pad > 0 && !cursor_memset(cur, 0, pad)) + return 0; + + return 1; +} + + #endif