Commit 75bb8ea0 authored by Karl Heyes's avatar Karl Heyes

merged from kh branch, allow for handling the vsnprintf return code better

on older systems.

svn path=/icecast/trunk/net/; revision=7917
parent 5080986d
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment