+ if (!advance) {
+ len = src->data - start_ptr;
+ silc_buffer_push(src, len);
+ }
+ return len;
+}
+
+
+/**************************** Utility functions *****************************/
+
+/* Formats strings into a buffer */
+
+int silc_buffer_strformat(SilcBuffer dst, ...)
+{
+ int len = silc_buffer_truelen(dst);
+ int hlen = silc_buffer_headlen(dst);
+ va_list va;
+
+ va_start(va, dst);
+
+ /* Parse the arguments by formatting type. */
+ while(1) {
+ char *string = va_arg(va, char *);
+ unsigned char *d;
+ SilcInt32 slen;
+
+ if (!string)
+ continue;
+ if (string == (char *)SILC_PARAM_END)
+ goto ok;
+
+ slen = strlen(string);
+ d = silc_realloc(dst->head, sizeof(*dst->head) * (slen + len + 1));
+ if (silc_unlikely(!d))
+ return -1;
+ dst->head = d;
+ memcpy(dst->head + len, string, slen);
+ len += slen;
+ dst->head[len] = '\0';
+ }
+
+ SILC_LOG_DEBUG(("Error occured while formatting buffer"));
+ va_end(va);
+ return -1;
+
+ ok:
+ dst->end = dst->head + len;
+ dst->data = dst->head + hlen;
+ dst->tail = dst->end;
+
+ va_end(va);
+ return len;
+}
+
+/* Formats strings into a buffer. Allocates memory from SilcStack. */
+
+int silc_buffer_sstrformat(SilcStack stack, SilcBuffer dst, ...)
+{
+ int len = silc_buffer_truelen(dst);
+ int hlen = silc_buffer_headlen(dst);
+ va_list va;
+
+ va_start(va, dst);
+
+ /* Parse the arguments by formatting type. */
+ while(1) {
+ char *string = va_arg(va, char *);
+ unsigned char *d;
+ SilcInt32 slen;
+
+ if (!string)
+ continue;
+ if (string == (char *)SILC_PARAM_END)
+ goto ok;
+
+ slen = strlen(string);
+ d = silc_srealloc(stack, len + 1, dst->head,
+ sizeof(*dst->head) * (slen + len + 1));
+ if (silc_unlikely(!d))
+ return -1;
+ dst->head = d;
+ memcpy(dst->head + len, string, slen);
+ len += slen;
+ dst->head[len] = '\0';
+ }
+
+ SILC_LOG_DEBUG(("Error occured while formatting buffer"));
+ va_end(va);
+ return -1;
+
+ ok:
+ dst->end = dst->head + len;
+ dst->data = dst->head + hlen;
+ dst->tail = dst->end;
+
+ va_end(va);