Improve buffer library to actually use a buffer.

Before the buffer library just used realloc repeatedly when a string was
appended. This patch makes the buffer library actually maintain a buffer.
Additionally, developers can pass a buffer (on the stack) to use, limit the
maximum size of the buffer, and have the buffer library call fatal on error.