[xiph-commits] r7908 - icecast/branches/kh/net

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Sat Oct 2 05:29:40 PDT 2004


Author: karl
Date: 2004-10-02 05:29:40 -0700 (Sat, 02 Oct 2004)
New Revision: 7908

Modified:
   icecast/branches/kh/net/sock.c
Log:
handle vnsprintf differently if a return of -1 indicates truncation


Modified: icecast/branches/kh/net/sock.c
===================================================================
--- icecast/branches/kh/net/sock.c	2004-10-02 12:22:16 UTC (rev 7907)
+++ icecast/branches/kh/net/sock.c	2004-10-02 12:29:40 UTC (rev 7908)
@@ -362,8 +362,35 @@
     return rc;
 }
 
+#ifdef HAVE_OLD_VSNPRINTF
 int sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
 {
+    va_list ap_local;
+    unsigned int len = 1024;
+    char *buff = NULL;
+    int ret;
+
+    /* don't go infinite, but stop at some hugh limit */
+    while (len < 5*1024*1024)
+    {
+        char *tmp = realloc (buff, len);
+        if (tmp == NULL)
+        {
+            free (buff);
+            return -1;
+        }
+        buff = tmp;
+        va_copy (ap_local, ap);
+        ret = vsnprintf (buff, len, fmt, ap_local);
+        if (ret > 0)
+            return sock_write_bytes (sock, buff, ret);
+        len += 8192;
+    }
+    return -1;
+}
+#else
+int sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
+{
     char buffer [1024], *buff = buffer;
     int len;
     int rc = SOCK_ERROR;
@@ -394,6 +421,7 @@
 
     return rc;
 }
+#endif
 
 
 /* function to check if there are any pending reads on



More information about the commits mailing list