[xiph-cvs] cvs commit: ices configure.in

Karl Heyes karl at xiph.org
Thu Jun 5 17:05:19 PDT 2003



karl        03/06/05 20:05:19

  Modified:    .        configure.in
               .        sock.c sock.h
               .        configure.in
               .        configure.in
  Log:
  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.

Revision  Changes    Path
1.44      +13 -1     libshout/configure.in

Index: configure.in
===================================================================
RCS file: /usr/local/cvsroot/libshout/configure.in,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- configure.in	5 Jun 2003 19:02:36 -0000	1.43
+++ configure.in	6 Jun 2003 00:05:18 -0000	1.44
@@ -1,5 +1,5 @@
 # Process this file with autoconf to produce a configure script.
-# $Id: configure.in,v 1.43 2003/06/05 19:02:36 brendan Exp $
+# $Id: configure.in,v 1.44 2003/06/06 00:05:18 karl Exp $
 
 m4_define(libshout_major, 2)
 m4_define(libshout_minor, 0)
@@ -109,6 +109,18 @@
   [#ifndef HAVE_SOCKLEN_T
 typedef int socklen_t;
 #endif])
+
+AC_MSG_CHECKING([how to copy va_list])
+AC_TRY_LINK([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);],
+        AC_MSG_RESULT([va_copy]),
+        [ 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_MSG_RESULT([__va_copy])],
+            [ AC_DEFINE([va_copy(dest,src)], [memcpy(&dest,&src,sizeof(va_list))])
+            AC_MSG_RESULT([memcpy])]
+            )
+        ])
 
 dnl Checks for library functions.
 AC_CHECK_FUNCS(nanosleep)

<p><p>1.27      +45 -10    net/sock.c

Index: sock.c
===================================================================
RCS file: /usr/local/cvsroot/net/sock.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- sock.c	5 Jun 2003 19:17:59 -0000	1.26
+++ sock.c	6 Jun 2003 00:05:18 -0000	1.27
@@ -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)
+ #else
+  #define va_copy(dest,src)    memcpy(&dest, &src, sizeof (va_list))
+ #endif
+#endif
+#endif
+
 /* sock_initialize
 **
 ** initializes the socket library.  you must call this
@@ -312,24 +322,49 @@
 */
 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);
-    va_end(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);
 
-    vsnprintf(buff, 1024, fmt, ap);
+    len = vsnprintf (buff, sizeof (buffer), fmt, ap);
 
-    return sock_write_bytes(sock, buff, strlen(buff));
+    if (len > 0)
+    {
+        if ((size_t)len < sizeof (buffer))   /* common case */
+            rc = sock_write_bytes(sock, buff, (size_t)len);
+        else
+        {
+            /* 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 rc;
 }
+
 
 int sock_read_bytes(sock_t sock, char *buff, const int len)
 {

<p><p>1.15      +1 -1      net/sock.h

Index: sock.h
===================================================================
RCS file: /usr/local/cvsroot/net/sock.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- sock.h	5 Jun 2003 17:09:12 -0000	1.14
+++ sock.h	6 Jun 2003 00:05:18 -0000	1.15
@@ -88,7 +88,7 @@
 /* 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);
 

<p><p>1.34      +11 -0     icecast/configure.in

Index: configure.in
===================================================================
RCS file: /usr/local/cvsroot/icecast/configure.in,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- configure.in	5 Jun 2003 17:55:40 -0000	1.33
+++ configure.in	6 Jun 2003 00:05:18 -0000	1.34
@@ -92,6 +92,17 @@
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
+AC_MSG_CHECKING([how to copy va_list])
+    AC_TRY_LINK([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);],
+            AC_MSG_RESULT([va_copy]),
+            [ 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_MSG_RESULT([__va_copy])],
+                [ AC_DEFINE([va_copy(dest,src)], [memcpy(&dest,&src,sizeof(va_list))])
+                AC_MSG_RESULT([memcpy])]
+                )
+            ])
 
 dnl Check for types
 AC_CHECK_TYPE([socklen_t], int)

<p><p>1.24      +12 -0     ices/configure.in

Index: configure.in
===================================================================
RCS file: /usr/local/cvsroot/ices/configure.in,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- configure.in	1 Apr 2003 02:36:08 -0000	1.23
+++ configure.in	6 Jun 2003 00:05:19 -0000	1.24
@@ -100,6 +100,18 @@
 #endif
 ])
 
+AC_MSG_CHECKING([how to copy va_list])
+    AC_TRY_LINK([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);],
+            AC_MSG_RESULT([va_copy]),
+            [ 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_MSG_RESULT([__va_copy])],
+                [ AC_DEFINE([va_copy(dest,src)], [memcpy(&dest,&src,sizeof(va_list))])
+                AC_MSG_RESULT([memcpy])]
+                )
+            ])
+
 dnl needs to be checked early on, so that additional libraries
 dnl don't trick the check
 ACX_PTHREAD([

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list