--------------------- PatchSet 10321 Date: 2007/12/27 12:59:08 Author: adri Branch: s27_adri Tag: (none) Log: A couple new buffer functions, useful later on. Members: libbuf/buf.c:1.1.2.7->1.1.2.8 libbuf/buf.h:1.1.2.5->1.1.2.6 Index: squid/libbuf/buf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/buf.c,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- squid/libbuf/buf.c 20 Dec 2007 10:32:38 -0000 1.1.2.7 +++ squid/libbuf/buf.c 27 Dec 2007 12:59:08 -0000 1.1.2.8 @@ -27,6 +27,7 @@ buf_pool = memPoolCreate("buf_t", sizeof(buf_t)); } + static int buf_changesize(buf_t *b, int newsize) { @@ -55,6 +56,19 @@ return 1; } +/* + * Grow the buffer to accomodate the given minimum free size. + * XXX Ideally we'll want to page size align the eventual allocation. + */ +int +buf_grow_to_min_free(buf_t *b, int minfree) +{ + if (buf_remainder(b) >= minfree) + return 0; + return buf_changesize(b, b->size + minfree); +} + + buf_t * buf_create(void) { Index: squid/libbuf/buf.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/buf.h,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- squid/libbuf/buf.h 19 Dec 2007 03:58:29 -0000 1.1.2.5 +++ squid/libbuf/buf.h 27 Dec 2007 12:59:09 -0000 1.1.2.6 @@ -32,6 +32,8 @@ extern int buf_fill(buf_t *buf, int fd, int dogrow); extern int buf_make_immutable(buf_t *buf, int offset); extern int buf_append(buf_t *buf, const void *src, size_t len, buf_flags_t flags); +extern int buf_grow_to_min_free(buf_t *b, int minfree); + static inline int buf_len(const buf_t *buf) { return buf->len; } @@ -41,6 +43,7 @@ #define buf_buf(buf) ((buf)->b) #define buf_len(buf) ((buf)->len) #define buf_refcnt(buf) ((buf)->nref) +#define buf_remainder(buf) ( (buf)->size - (buf)->len ) static inline int buf_get_chr(const buf_t *buf, int offset) {