Update of /cvsroot/tmux/tmux/compat
In directory vz-cvs-2.sog:/tmp/cvs-serv11878

Modified Files:
        asprintf.c 
Log Message:
Use the right asprintf since we don't support truly broken platforms right now.

Index: asprintf.c
===================================================================
RCS file: /cvsroot/tmux/tmux/compat/asprintf.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- asprintf.c  21 Jan 2011 20:03:18 -0000      1.6
+++ asprintf.c  4 Mar 2011 23:39:41 -0000       1.7
@@ -28,13 +28,13 @@
 #include "tmux.h"
 
 int
-asprintf(char **ret, const char *format, ...)
+asprintf(char **ret, const char *fmt, ...)
 {
        va_list ap;
        int     n;
 
-       va_start(ap, format);
-       n = vasprintf(ret, format, ap);
+       va_start(ap, fmt);
+       n = vasprintf(ret, fmt, ap);
        va_end(ap);
 
        return (n);
@@ -43,28 +43,20 @@
 int
 vasprintf(char **ret, const char *fmt, va_list ap)
 {
-       va_list       aq;
-       size_t        len;
-       char         *buf;
-       int           n;
+       int      n;
 
-       len = 64;
-       buf = xmalloc(len);
+       if ((n = vsnprintf(NULL, 0, fmt, ap)) < 0)
+               goto error;
 
-       for (;;) {
-               va_copy(aq, ap);
-               n = vsnprintf(buf, len, fmt, aq);
-               va_end(aq);
+       *ret = xmalloc(n + 1);
+       if ((n = vsnprintf(*ret, n + 1, fmt, ap)) < 0) {
+               xfree(*ret);
+               goto error;
+       }
 
-               if (n != -1) {
-                       *ret = buf;
-                       return (n);
-               }
+       return (n);
 
-               if (len > SIZE_MAX / 2) {
-                       xfree(buf);
-                       return (-1);
-               }
-               len *= 2;
-       }
+error:
+       *ret = NULL;
+       return (-1);
 }


------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to