+/*
+
+@deftypefn Extension char* reconcat (char *@var{optr}, const char *@var{s1}, @
+ @dots{}, @code{NULL})
+
+Same as @code{concat}, except that if @var{optr} is not @code{NULL} it
+is freed after the string is created. This is intended to be useful
+when you're extending an existing string or building up a string in a
+loop:
+
+@example
+ str = reconcat (str, "pre-", str, NULL);
+@end example
+
+@end deftypefn
+
+*/
+
+char *
+reconcat (char *optr, const char *first, ...)
+{
+ char *newstr;
+ va_list args;
+
+ /* First compute the size of the result and get sufficient memory. */
+ va_start (args, first);
+ newstr = XNEWVEC (char, vconcat_length (first, args) + 1);
+ va_end (args);
+
+ /* Now copy the individual pieces to the result string. */
+ va_start (args, first);
+ vconcat_copy (newstr, first, args);
+ if (optr) /* Done before VA_CLOSE so optr stays in scope for K&R C. */
+ free (optr);
+ va_end (args);
+
+ return newstr;