mirror of
https://github.com/tmux/tmux.git
synced 2024-12-24 18:28:56 +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>
|
||||
@ -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 @@ asprintf(char **ret, const char *format, ...)
|
||||
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);
|
||||
|
||||
if (n != -1) {
|
||||
*ret = buf;
|
||||
return (n);
|
||||
}
|
||||
|
||||
if (len > SIZE_MAX / 2) {
|
||||
xfree(buf);
|
||||
return (-1);
|
||||
}
|
||||
len *= 2;
|
||||
*ret = xmalloc(n + 1);
|
||||
if ((n = vsnprintf(*ret, n + 1, fmt, ap)) < 0) {
|
||||
xfree(*ret);
|
||||
goto error;
|
||||
}
|
||||
|
||||
return (n);
|
||||
|
||||
error:
|
||||
*ret = NULL;
|
||||
return (-1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user