tidying
[exim.git] / src / src / string.c
index 2e919e6d9761451b7665c7f4643aa929df41a184..112c2adc32c3892479f39bea4d512c0041b5c569 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2017 */
+/* Copyright (c) University of Cambridge 1995 - 2018 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 /* Miscellaneous string-handling functions. Some are not required for
@@ -701,7 +701,7 @@ return yield;
 *          Format a string and save it           *
 *************************************************/
 
-/* The formatting is done by string_format, which checks the length of
+/* The formatting is done by string_vformat, which checks the length of
 everything.
 
 Arguments:
@@ -914,7 +914,7 @@ sep_is_special = iscntrl(sep);
 
 /* Handle the case when a buffer is provided. */
 
-if (buffer != NULL)
+if (buffer)
   {
   int p = 0;
   for (; *s != 0; s++)
@@ -960,6 +960,7 @@ else
     }
   while (g->ptr > 0 && isspace(g->s[g->ptr-1])) g->ptr--;
   buffer = string_from_gstring(g);
+  gstring_reset_unused(g);
   }
 
 /* Update the current pointer and return the new string */
@@ -1050,6 +1051,24 @@ return list;
 
 
 
+/* A slightly-bogus listmaker utility; the separator is a string so
+can be multiple chars - there is no checking for the element content
+containing any of the separator. */
+
+gstring *
+string_append2_listele_n(gstring * list, const uschar * sepstr,
+ const uschar * ele, unsigned len)
+{
+if (list && list->ptr)
+  list = string_cat(list, sepstr);
+
+list = string_catn(list, ele, len);
+(void) string_from_gstring(list);
+return list;
+}
+
+
+
 /************************************************/
 /* Create a growable-string with some preassigned space */
 
@@ -1073,11 +1092,23 @@ g->s[g->ptr] = '\0';
 return g->s;
 }
 
+void
+gstring_reset_unused(gstring * g)
+{
+store_reset(g->s + (g->size = g->ptr + 1));
+}
+
 /*************************************************
 *             Add chars to string                *
 *************************************************/
 
-void
+/* Arguments:
+  g            the grawable-string
+  p            current end of data
+  count                amount to grow by
+*/
+
+static void
 gstring_grow(gstring * g, int p, int count)
 {
 int oldsize = g->size;
@@ -1102,13 +1133,7 @@ was the last item on the dynamic memory stack. This is the case if it matches
 store_last_get. */
 
 if (!store_extend(g->s, oldsize, g->size))
-  {
-  BOOL release_ok = store_last_get[store_pool] == g->s;
-  uschar *newstring = store_get(g->size);
-  memcpy(newstring, g->s, p);
-  if (release_ok) store_release(g->s);
-  g->s = newstring;
-  }
+  g->s = store_newblock(g->s, g->size, p);
 }