$OpenBSD: patch-src_util_str_c,v 1.1 2021/09/20 15:47:12 tb Exp $

Index: src/util_str.c
--- src/util_str.c.orig
+++ src/util_str.c
@@ -303,6 +303,42 @@ const char *s_sprintf (const char *fmt, ...)
 }
 
 /*
+ * Return a static formatted string and length
+ */
+const char *s_sprintf_len (int *lenp, const char *fmt, ...)
+{
+    static char *buf = NULL;
+    static int size = 0;
+    va_list args;
+    char *nbuf;
+    int rc, nsize;
+
+    if (!buf)
+        buf = calloc (1, size = 1024);
+
+    while (1)
+    {
+        buf[size - 2] = '\0';
+        va_start (args, fmt);
+        rc = vsnprintf (buf, size, fmt, args);
+        va_end (args);
+        
+        if (rc >= 0 && rc < size && !buf[size - 2])
+            break;
+
+        nsize = (rc > 0 ? rc + 5 : size * 2);
+        nbuf = malloc (nsize);
+        if (!nbuf)
+            break;
+        free (buf);
+        buf = nbuf;
+        size = nsize;
+    }
+    *lenp = rc;
+    return buf;
+}
+
+/*
  * Return a static string consisting of the given IP.
  */
 const char *s_ip (UDWORD ip)
