aboutsummaryrefslogtreecommitdiff
path: root/compat/asprintf.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-23 21:54:48 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-23 21:54:48 +0000
commite704d6aee2b9e8864589d1960ac15726bb0cd35c (patch)
treebe4a1d78a3f9f58ee244dd407d8d1be1032f5506 /compat/asprintf.c
parent14d7cf3878360dd47ec3e22cdf4e3d731797c9de (diff)
downloadrtmux-e704d6aee2b9e8864589d1960ac15726bb0cd35c.tar.gz
rtmux-e704d6aee2b9e8864589d1960ac15726bb0cd35c.tar.bz2
rtmux-e704d6aee2b9e8864589d1960ac15726bb0cd35c.zip
IRIX fixes, sort of partly work.
Diffstat (limited to 'compat/asprintf.c')
-rw-r--r--compat/asprintf.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/compat/asprintf.c b/compat/asprintf.c
index f3ec7ef7..05e8dd24 100644
--- a/compat/asprintf.c
+++ b/compat/asprintf.c
@@ -1,4 +1,4 @@
-/* $Id: asprintf.c,v 1.2 2008-06-18 22:21:51 nicm Exp $ */
+/* $Id: asprintf.c,v 1.3 2008-06-23 21:54:48 nicm Exp $ */
/*
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -16,7 +16,9 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <stdarg.h>
#include <stdio.h>
+#include <stdint.h>
#include <string.h>
#include "tmux.h"
@@ -34,6 +36,7 @@ asprintf(char **ret, const char *format, ...)
return (n);
}
+#ifndef BROKEN_VSNPRINTF
int
vasprintf(char **ret, const char *format, va_list ap)
{
@@ -54,3 +57,33 @@ error:
*ret = NULL;
return (-1);
}
+#else
+int
+vasprintf(char **ret, const char *fmt, va_list ap)
+{
+ va_list aq;
+ size_t len;
+ char *buf;
+ int n;
+
+ len = 64;
+ buf = xmalloc(len);
+
+ for (;;) {
+ va_copy(aq, ap);
+ n = vsnprintf(buf, len, fmt, aq);
+ va_end(aq);
+
+ if (n != -1) {
+ *ret = buf;
+ return (n);
+ }
+
+ if (len > SIZE_MAX / 2) {
+ xfree(buf);
+ return (-1);
+ }
+ len *= 2;
+ }
+}
+#endif