nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 09401e5f35ed940019865b7ec40da3e18d2e3480
parent ad5bcd87a47aebf003f56832ffdbb03eab275669
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 27 Dec 2023 12:41:59 -0800

cursor: add align function

handy function for padding buffers to some byte alignment

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

diff --git a/src/cursor.h b/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