]> granicus.if.org Git - mutt/commitdiff
Create mutt_buffer_increase_size() function.
authorKevin McCarthy <kevin@8t8.us>
Sat, 26 May 2018 21:46:16 +0000 (14:46 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sun, 12 Aug 2018 01:20:56 +0000 (18:20 -0700)
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.

muttlib.c
protos.h

index 2b48f3b84f4fba0a036df6009fde10ba2bc0f543..75495dee4bf3a1883d90bb222e55180b28e6740a 100644 (file)
--- 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
index c44ebecbc847315778d4039c93d05ec8c2a4d460..c112d888201ca23199c4a71358df8464d7eefc49 100644 (file)
--- 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*, ...);