mirror of
https://github.com/tmux/tmux.git
synced 2024-12-25 19:08:58 +00:00
Use the right asprintf since we don't support truly broken platforms right now.
This commit is contained in:
parent
4cb976b408
commit
34bb013b92
@ -1,4 +1,4 @@
|
|||||||
/* $Id: asprintf.c,v 1.6 2011-01-21 20:03:18 nicm Exp $ */
|
/* $Id: asprintf.c,v 1.7 2011-03-04 23:39:41 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -28,13 +28,13 @@
|
|||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
asprintf(char **ret, const char *format, ...)
|
asprintf(char **ret, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, fmt);
|
||||||
n = vasprintf(ret, format, ap);
|
n = vasprintf(ret, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return (n);
|
return (n);
|
||||||
@ -43,28 +43,20 @@ asprintf(char **ret, const char *format, ...)
|
|||||||
int
|
int
|
||||||
vasprintf(char **ret, const char *fmt, va_list ap)
|
vasprintf(char **ret, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
va_list aq;
|
|
||||||
size_t len;
|
|
||||||
char *buf;
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
len = 64;
|
if ((n = vsnprintf(NULL, 0, fmt, ap)) < 0)
|
||||||
buf = xmalloc(len);
|
goto error;
|
||||||
|
|
||||||
for (;;) {
|
*ret = xmalloc(n + 1);
|
||||||
va_copy(aq, ap);
|
if ((n = vsnprintf(*ret, n + 1, fmt, ap)) < 0) {
|
||||||
n = vsnprintf(buf, len, fmt, aq);
|
xfree(*ret);
|
||||||
va_end(aq);
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (n != -1) {
|
|
||||||
*ret = buf;
|
|
||||||
return (n);
|
return (n);
|
||||||
}
|
|
||||||
|
|
||||||
if (len > SIZE_MAX / 2) {
|
error:
|
||||||
xfree(buf);
|
*ret = NULL;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
|
||||||
len *= 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user