1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

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

on older systems.

svn path=/icecast/trunk/net/; revision=7917
This commit is contained in:
Karl Heyes 2004-10-06 14:07:55 +00:00
parent 5080986dc4
commit 75bb8ea0ce

View File

@ -362,6 +362,35 @@ int sock_write(sock_t sock, const char *fmt, ...)
return rc; 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) int sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
{ {
char buffer [1024], *buff = buffer; char buffer [1024], *buff = buffer;
@ -394,6 +423,7 @@ int sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
return rc; return rc;
} }
#endif
int sock_read_bytes(sock_t sock, char *buff, const int len) int sock_read_bytes(sock_t sock, char *buff, const int len)