The strbuf library that's part of git.git is a pleasure to work with. It's C-string compatible (just a char
/size_t pair), guarantees that the "char " member is always NULL-delimited, but can also be used for binary data. It also guarantees that the "buf" member is never NULL:
https://github.com/git/git/blob/v2.34.0/strbuf.h#L6-L70