From: Victor Julien Date: Fri, 24 Nov 2023 15:10:16 +0000 (+0100) Subject: membuffer: return bytes written X-Git-Tag: suricata-7.0.7~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9670c3016bebdab05240128e9fd10b1d55207787;p=thirdparty%2Fsuricata.git membuffer: return bytes written (cherry picked from commit 7d5b537f5cec0e88d4442a81500254b98004f117) --- diff --git a/src/util-buffer.c b/src/util-buffer.c index 5b52a05dc4..05b3658258 100644 --- a/src/util-buffer.c +++ b/src/util-buffer.c @@ -109,7 +109,7 @@ void MemBufferPrintToFPAsHex(MemBuffer *b, FILE *fp) } } -void MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len) +uint32_t MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len) { uint32_t write_len; if (raw_len >= dst->size - dst->offset) { @@ -121,6 +121,7 @@ void MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_le memcpy(dst->buffer + dst->offset, raw, write_len); dst->offset += write_len; dst->buffer[dst->offset] = '\0'; + return write_len; } void MemBufferWriteString(MemBuffer *dst, const char *fmt, ...) diff --git a/src/util-buffer.h b/src/util-buffer.h index e58a790d7b..58bee05397 100644 --- a/src/util-buffer.h +++ b/src/util-buffer.h @@ -111,8 +111,9 @@ void MemBufferPrintToFPAsHex(MemBuffer *b, FILE *fp); * * \param raw_buffer The buffer to write. * \param raw_buffer_len Length of the above buffer. + * \retval write_len Bytes written. If less than raw_len, the buffer is full. */ -void MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len); +uint32_t MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len); /** * \brief Write a string buffer to the Membuffer dst.