X-Git-Url: http://git.squeep.com/?p=reservoir_sample;a=blobdiff_plain;f=buf.h;fp=buf.h;h=70a1ae524538e04fcca415f6b0f2d411a3b0fa06;hp=a47f3ba154d38ec7958fe0f70905f19fb91c8257;hb=ee831dbcdf31c3d1205bc321a8bdbeeb151abe19;hpb=c8ff35a649a7df3d400221fc76131bff195a158b diff --git a/buf.h b/buf.h index a47f3ba..70a1ae5 100644 --- a/buf.h +++ b/buf.h @@ -7,7 +7,7 @@ #include "notify.h" #endif /* NDEBUG */ -/* A simple sliding-window byte buffer. */ +/* A simple sliding-window byte buffer. */ typedef struct buf_ { size_t buf_sz; @@ -18,6 +18,7 @@ typedef struct buf_ { #define BUF_ROOM(__b__) ( (__b__)->buf_sz - ( (__b__)->buf_start + (__b__)->buf_used ) ) #ifndef NDEBUG +/* For debugging, dump a buffer. */ #define D_BUF(__pre__,__b__,...) do {\ if ( (__b__) == NULL )\ NOTIFY_DEBUG(__pre__ "buf:%p", ## __VA_ARGS__, (__b__));\ @@ -37,29 +38,35 @@ typedef struct buf_ { #define D_BUF(...) #endif /* NDEBUG */ -/* buf_new - Allocate and return a new buf_t capable of holding #sz bytes. +/* buf_new + Allocate and return a new buf_t capable of holding #sz bytes. */ buf_t buf_new(size_t sz); -/* buf_rebase - Reclaim any free space from the start of #buf, preserving active content. +/* buf_del + Deallocate the buf_t pointed to by #pbuf. +*/ +void buf_del(buf_t *pbuf); + +/* buf_rebase + Reclaim any free space from the start of #buf, preserving active content. */ void buf_rebase(buf_t buf); -/* buf_makeroom - Assures that the buf pointed to by #pbuf has at space to hold #roomfor more - bytes. +/* buf_makeroom + Assures that the buf pointed to by #pbuf has at space to hold #roomfor + more bytes. */ int buf_makeroom(buf_t *pbuf, size_t roomfor); -/* buf_range_dup_or_append - Starting at the #src_offset byte of #src, appends the following #n bytes to - the buffer pointed to by #dstp, which will be re/allocated if needed. +/* buf_range_dup_or_append + Starting at the #src_offset byte of #src, appends the following #n + bytes to the buffer pointed to by #dstp, which will be re/allocated if + needed. */ int buf_range_dup_or_append(buf_t src, size_t src_offset, size_t n, buf_t *pdst); -/* buf_flense +/* buf_flense Starting after #src_offset characters, scan through the buffer pointed to by #psrc, stopping at the first byte matching #delimiter, whereupon, if #pdst is not NULL, all the bytes previous to #delimiter are appended onto