From 523cc5d5060782dc379c69d0349a7b5c2c4aaf0e Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 9 Jul 2018 10:32:29 +0200 Subject: [PATCH] MINOR: buffer: convert part bo_putblk() and bi_putblk() to the new API These functions are pretty similar and will be merged at the end of the migration. For now they still need to remain distinct. --- include/common/buffer.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/include/common/buffer.h b/include/common/buffer.h index e43969c..86eec16 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -140,17 +140,16 @@ static inline void bo_putchr(struct buffer *b, char c) b->o++; } -/* Tries to copy block into output data at buffer . Supports wrapping. +/* Tries to append block at the end of buffer . Supports wrapping. * Data are truncated if buffer is too short. It returns the number of bytes * copied. */ -static inline int bo_putblk(struct buffer *b, const char *blk, int len) +static inline unsigned int bo_putblk(struct buffer *b, const char *blk, unsigned int len) { - int cur_len = b_data(b); - int half; + unsigned int half; - if (len > b->size - cur_len) - len = (b->size - cur_len); + if (len > b_room(b)) + len = b_room(b); if (!len) return 0; @@ -158,11 +157,11 @@ static inline int bo_putblk(struct buffer *b, const char *blk, int len) if (half > len) half = len; - memcpy(b->p, blk, half); + memcpy(b_tail(b), blk, half); b->p = b_peek(b, b->o + half); b->o += half; if (len > half) { - memcpy(b->p, blk + half, len - half); + memcpy(b_tail(b), blk + half, len - half); b->p = b_peek(b, b->o + len - half); b->o += len - half; } @@ -198,17 +197,16 @@ static inline void bi_putchr(struct buffer *b, char c) b->i++; } -/* Tries to copy block into input data at buffer . Supports wrapping. +/* Tries to append block at the end of buffer . Supports wrapping. * Data are truncated if buffer is too short. It returns the number of bytes * copied. */ -static inline int bi_putblk(struct buffer *b, const char *blk, int len) +static inline unsigned int bi_putblk(struct buffer *b, const char *blk, unsigned int len) { - int cur_len = b_data(b); int half; - if (len > b->size - cur_len) - len = (b->size - cur_len); + if (len > b_room(b)) + len = b_room(b); if (!len) return 0; @@ -217,9 +215,11 @@ static inline int bi_putblk(struct buffer *b, const char *blk, int len) half = len; memcpy(b_tail(b), blk, half); - if (len > half) - memcpy(b_peek(b, b->o + b->i + half), blk + half, len - half); - b->i += len; + b->i += half; + if (len > half) { + memcpy(b_tail(b), blk + half, len - half); + b->i += len - half; + } return len; } -- 1.7.10.4