#include <cat.h>
int catbuf_block(cat_buffer *b, unsigned char **block);
catbuf_block() retrieves a pointer to the next block in b starting at the current index, and returns the length of the block. The pointer is returned in the variable pointed to by block. Note that blocks may be of zero length.
When no more blocks remain, -1 is returned.
This function accesses the blocks in the order in which they are stored inside the buffer data structure. No buffer-modifying functions should be used between two calls to this function.
int n; unsigned char *p;
catbuf_index(b, 0); while ((n = catbuf_block(b, &p)) > -1) { if (n > 0) { fwrite(p, 1, n, f); } }