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