Add function to append n bytes

This adds a function to add the first N bytes from a string into a buffer.
I don't know this code base well, but don't we want `strlen(str) + 1` for the `NULL`?