Commit f6e85339 authored by Karl Heyes's avatar Karl Heyes
Browse files

Another net change, making it more bullet-proof, before could silently miss

data. so now we allocate enough space for the write to succeed fully.

svn path=/trunk/libshout/; revision=4888
parent f21cc317
# Process this file with autoconf to produce a configure script.
# $Id:,v 1.43 2003/06/05 19:02:36 brendan Exp $
# $Id:,v 1.44 2003/06/06 00:05:18 karl Exp $
m4_define(libshout_major, 2)
m4_define(libshout_minor, 0)
......@@ -110,6 +110,18 @@ AH_VERBATIM([X_HAVE_SOCKLEN_T],
typedef int socklen_t;
AC_MSG_CHECKING([how to copy va_list])
AC_TRY_LINK([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);],
[ AH_TEMPLATE([va_copy], [define if va_copy is not available])
AC_TRY_LINK([#include <stdarg.h>], [va_list ap1, ap2; __va_copy(ap1, ap2);],
[ AC_DEFINE([va_copy], [__va_copy])
[ AC_DEFINE([va_copy(dest,src)], [memcpy(&dest,&src,sizeof(va_list))])
dnl Checks for library functions.
AC_CHECK_FUNCS(sethostent endhostent)
......@@ -57,6 +57,16 @@
#include "sock.h"
#include "resolver.h"
#if 0
#ifndef HAVE_VA_COPY
#ifdef HAVE___VA_COPY
#define va_copy(dest,src) __va_copy(dest, src)
#define va_copy(dest,src) memcpy(&dest, &src, sizeof (va_list))
/* sock_initialize
** initializes the socket library. you must call this
......@@ -312,25 +322,50 @@ int sock_write_string(sock_t sock, const char *buff)
int sock_write(sock_t sock, const char *fmt, ...)
char buff[1024];
int rc;
va_list ap;
va_start(ap, fmt);
vsnprintf(buff, 1024, fmt, ap);
return sock_write_bytes(sock, buff, strlen(buff));
va_start (ap, fmt);
rc = sock_write_fmt (sock, fmt, ap);
va_end (ap);
return rc;
int sock_write_fmt(sock_t sock, char *fmt, va_list ap)
int sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
char buff[1024];
char buffer [1024], *buff = buffer;
int len;
int rc = SOCK_ERROR;
va_list ap_retry;
va_copy (ap_retry, ap);
len = vsnprintf (buff, sizeof (buffer), fmt, ap);
vsnprintf(buff, 1024, fmt, ap);
if (len > 0)
if ((size_t)len < sizeof (buffer)) /* common case */
rc = sock_write_bytes(sock, buff, (size_t)len);
/* truncated */
buff = malloc (++len);
if (buff)
len = vsnprintf (buff, len, fmt, ap_retry);
va_end (ap_retry);
if (len > 0)
rc = sock_write_bytes (sock, buff, len);
free (buff);
return sock_write_bytes(sock, buff, strlen(buff));
return rc;
int sock_read_bytes(sock_t sock, char *buff, const int len)
......@@ -88,7 +88,7 @@ int sock_connected (int sock, unsigned timeout);
/* Socket write functions */
int sock_write_bytes(sock_t sock, const void *buff, const size_t len);
int sock_write(sock_t sock, const char *fmt, ...);
int sock_write_fmt(sock_t sock, char *fmt, va_list ap);
int sock_write_fmt(sock_t sock, const char *fmt, va_list ap);
int sock_write_string(sock_t sock, const char *buff);
ssize_t sock_writev (int sock, const struct iovec *iov, const size_t count);
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