10 /* A simple sliding-window byte buffer. */
18 #define BUF_ROOM(__b__) ( (__b__)->buf_sz - ( (__b__)->buf_start + (__b__)->buf_used ) )
21 #define D_BUF(__pre__,__b__,...) do {\
22 if ( (__b__) == NULL )\
23 NOTIFY_DEBUG(__pre__ "buf:%p", ## __VA_ARGS__, (__b__));\
25 NOTIFY_DEBUG(__pre__ "buf:%p sz:%zu start:%zu used:%zu free:%zu '%.*s'",\
32 (int)(__b__)->buf_used, (__b__)->buf + (__b__)->buf_start);\
33 assert( (__b__)->buf_sz >= (__b__)->buf_start + (__b__)->buf_used );\
41 Allocate and return a new buf_t capable of holding #sz bytes.
43 buf_t
buf_new(size_t sz
);
46 Reclaim any free space from the start of #buf, preserving active content.
48 void buf_rebase(buf_t buf
);
51 Assures that the buf pointed to by #pbuf has at space to hold #roomfor more
54 int buf_makeroom(buf_t
*pbuf
, size_t roomfor
);
56 /* buf_range_dup_or_append
57 Starting at the #src_offset byte of #src, appends the following #n bytes to
58 the buffer pointed to by #dstp, which will be re/allocated if needed.
60 int buf_range_dup_or_append(buf_t src
, size_t src_offset
, size_t n
, buf_t
*pdst
);
63 Starting after #src_offset characters, scan through the buffer pointed
64 to by #psrc, stopping at the first byte matching #delimiter, whereupon, if
65 #pdst is not NULL, all the bytes previous to #delimiter are appended onto
66 the buffer pointed to by *#pdst. The buffer pointed to by #psrc is then
67 trimmed to only contain the bytes following #delimiter. The delimiter byte
69 Returns the number of characters flensed from #src.
71 ssize_t
buf_flense(buf_t
*psrc
, size_t src_offset
, int delimiter
, buf_t
*pdst
);
73 #endif /* BUF_H_B87OZOFU */