From 75bb8ea0ce29111c682b96314f7ac8d0ad2df263 Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Wed, 6 Oct 2004 14:07:55 +0000 Subject: [PATCH] merged from kh branch, allow for handling the vsnprintf return code better on older systems. svn path=/icecast/trunk/net/; revision=7917 --- src/net/sock.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/net/sock.c b/src/net/sock.c index 0425037d..3fdb1488 100644 --- a/src/net/sock.c +++ b/src/net/sock.c @@ -362,6 +362,35 @@ int sock_write(sock_t sock, const char *fmt, ...) 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 huge limit */ + while (len < 2*1024*1024) + { + char *tmp = realloc (buff, len); + ret = -1; + if (tmp == NULL) + break; + buff = tmp; + va_copy (ap_local, ap); + ret = vsnprintf (buff, len, fmt, ap_local); + if (ret > 0) + { + ret = sock_write_bytes (sock, buff, ret); + break; + } + len += 8192; + } + free (buff); + return ret; +} +#else int sock_write_fmt(sock_t sock, const char *fmt, va_list ap) { char buffer [1024], *buff = buffer; @@ -394,6 +423,7 @@ int sock_write_fmt(sock_t sock, const char *fmt, va_list ap) return rc; } +#endif int sock_read_bytes(sock_t sock, char *buff, const int len)