We use the return value of the callback to track the number of bytes written. We use it to determine if a group of characters should be prepended with a whitespace. This way, we never add a trailing whitespace.
We need to pay attention to the return value of the callback: if it is negative, it's an error and we return immediately. Otherwise, we would decrease the number of written bytes and possibly make it negative.
Sponsored by: The FreeBSD Foundation