From: Kevin McCarthy Date: Sat, 26 May 2018 21:46:16 +0000 (-0700) Subject: Create mutt_buffer_increase_size() function. X-Git-Tag: mutt-1-11-rel~100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b13a4ba69ed4a704cb2d387d91ef011873bf2a46;p=mutt Create mutt_buffer_increase_size() function. This will allow preallocating buffers that we know are going to be big for qresync support. This will also be useful for buffer pools later on. --- diff --git a/muttlib.c b/muttlib.c index 2b48f3b8..75495dee 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1805,6 +1805,20 @@ BUFFER *mutt_buffer_init (BUFFER *b) { return b; } +/* Increases the allocated size of the buffer */ +void mutt_buffer_increase_size (BUFFER *buf, size_t new_size) +{ + size_t offset; + + if (buf->dsize < new_size) + { + offset = buf->dptr - buf->data; + buf->dsize = new_size; + safe_realloc (&buf->data, buf->dsize); + buf->dptr = buf->data + offset; + } +} + /* * Creates and initializes a BUFFER*. If passed an existing BUFFER*, * just initializes. Frees anything already in the buffer. Copies in diff --git a/protos.h b/protos.h index c44ebecb..c112d888 100644 --- a/protos.h +++ b/protos.h @@ -41,6 +41,7 @@ void mutt_make_string_info (char *, size_t, int, const char *, struct hdr_format int mutt_extract_token (BUFFER *, BUFFER *, int); BUFFER *mutt_buffer_new (void); BUFFER * mutt_buffer_init (BUFFER *); +void mutt_buffer_increase_size (BUFFER *, size_t); BUFFER * mutt_buffer_from (char *); void mutt_buffer_free(BUFFER **); int mutt_buffer_printf (BUFFER*, const char*, ...);