From dc4836c15c564534eedd651cdb5c3c54044f071f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 27 Feb 2024 19:52:00 +0100 Subject: [PATCH] MINOR: ring: add ring_dup() to copy a ring into another one This will mostly be used during reallocation and boot-time duplicates, the purpose is simply to save the caller from having to know the details of the internal representation. --- include/haproxy/ring.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/haproxy/ring.h b/include/haproxy/ring.h index b0add1d0c..81440f538 100644 --- a/include/haproxy/ring.h +++ b/include/haproxy/ring.h @@ -57,6 +57,21 @@ static inline size_t ring_size(const struct ring *ring) return b_size(&ring->buf); } +/* duplicates ring over ring for no more than bytes or no + * more than the amount of data present in . It's assumed that the + * destination ring is always large enough for . The number of bytes + * copied (the min of src's size and max) is returned. + */ +static inline size_t ring_dup(struct ring *dst, const struct ring *src, size_t max) +{ + if (max > ring_data(src)) + max = ring_data(src); + + b_reset(&dst->buf); + b_ncat(&dst->buf, &src->buf, max); + return max; +} + #endif /* _HAPROXY_RING_H */ /*