From 549aac8d0b32ddcd06ede62d103f9d304041a3ee Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER Date: Fri, 6 Feb 2015 18:40:20 +0100 Subject: [PATCH] MEDIUM: buffer: make bo_putblk/bo_putstr/bo_putchk return the number of bytes copied. This is not used yet. Planned for LUA. --- include/common/buffer.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/common/buffer.h b/include/common/buffer.h index 346521a55..446bd1a9b 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -354,9 +354,10 @@ static inline void bo_putchr(struct buffer *b, char c) } /* Tries to copy block into output data at buffer . Supports wrapping. - * Data are truncated if buffer is too short. + * Data are truncated if buffer is too short. It returns the number of bytes + * copied. */ -static inline void bo_putblk(struct buffer *b, const char *blk, int len) +static inline int bo_putblk(struct buffer *b, const char *blk, int len) { int cur_len = buffer_len(b); int half; @@ -364,7 +365,7 @@ static inline void bo_putblk(struct buffer *b, const char *blk, int len) if (len > b->size - cur_len) len = (b->size - cur_len); if (!len) - return; + return 0; half = buffer_contig_space(b); if (half > len) @@ -377,20 +378,23 @@ static inline void bo_putblk(struct buffer *b, const char *blk, int len) b->p = b_ptr(b, half); } b->o += len; + return len; } /* Tries to copy string into output data at buffer . Supports wrapping. - * Data are truncated if buffer is too short. + * Data are truncated if buffer is too short. It returns the number of bytes + * copied. */ -static inline void bo_putstr(struct buffer *b, const char *str) +static inline int bo_putstr(struct buffer *b, const char *str) { return bo_putblk(b, str, strlen(str)); } /* Tries to copy chunk into output data at buffer . Supports wrapping. - * Data are truncated if buffer is too short. + * Data are truncated if buffer is too short. It returns the number of bytes + * copied. */ -static inline void bo_putchk(struct buffer *b, const struct chunk *chk) +static inline int bo_putchk(struct buffer *b, const struct chunk *chk) { return bo_putblk(b, chk->str, chk->len); }