a more proper replacement for vasprintf. Lets see if we can actually do it this way (seems to work on msvc which is the only platform I have seen that does not have vasprintf available).
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4762 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
dc765f457e
commit
db9e1c549b
|
@ -608,79 +608,28 @@ SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t *queue, void
|
||||||
return apr_queue_trypush(queue, data);
|
return apr_queue_trypush(queue, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
SWITCH_DECLARE(int) switch_vasprintf(char **ret, const char *fmt, va_list ap)
|
||||||
/* Utility functions */
|
|
||||||
struct switch_vasprintf_data {
|
|
||||||
apr_vformatter_buff_t vbuff;
|
|
||||||
switch_size_t len;
|
|
||||||
switch_size_t block_size;
|
|
||||||
char *buf;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int vasprintf_flush(apr_vformatter_buff_t *buff)
|
|
||||||
{
|
{
|
||||||
struct switch_vasprintf_data *data = (struct switch_vasprintf_data *)buff;
|
|
||||||
|
|
||||||
char *temp;
|
|
||||||
switch_size_t len = data->vbuff.curpos - data->buf;
|
|
||||||
|
|
||||||
if ((temp = realloc(data->buf, data->len + data->block_size))) {
|
|
||||||
data->buf = temp;
|
|
||||||
data->vbuff.curpos = data->buf + len;
|
|
||||||
data->len = data->len + data->block_size;
|
|
||||||
data->vbuff.endpos = data->buf + data->len;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SWITCH_DECLARE(int) switch_vasprintf(char **buf, const char *format, va_list ap)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
struct switch_vasprintf_data data;
|
|
||||||
|
|
||||||
data.block_size = 1024;
|
|
||||||
data.buf = malloc(data.block_size);
|
|
||||||
|
|
||||||
if (data.buf == NULL) {
|
|
||||||
*buf = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.vbuff.curpos = data.buf;
|
|
||||||
data.vbuff.endpos = data.buf + data.block_size;
|
|
||||||
|
|
||||||
return apr_vformatter(vasprintf_flush, (apr_vformatter_buff_t *)&data, format, ap);
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_VASPRINTF
|
#ifdef HAVE_VASPRINTF
|
||||||
return vasprintf(buf, format, ap);
|
return vasprintf(ret, fmt, ap);
|
||||||
#else
|
#else
|
||||||
size_t block_size = 1024;
|
char *buf;
|
||||||
int ret = -1;
|
int len;
|
||||||
int count = 1;
|
size_t buflen;
|
||||||
*buf = (char *) malloc(block_size);
|
|
||||||
|
|
||||||
if (*buf == NULL) {
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
if (len > 0) {
|
||||||
|
buflen = (size_t)(len + 1);
|
||||||
|
if ((buf = malloc(buflen)) == NULL) {
|
||||||
|
*ret = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
len = vsnprintf(buf, buflen, fmt, ap);
|
||||||
while (ret == -1 && count < 10) {
|
*ret = buf;
|
||||||
ret = vsnprintf(*buf, block_size*count, format, ap);
|
|
||||||
if (ret == -1) {
|
|
||||||
void *new_buf;
|
|
||||||
count++;
|
|
||||||
new_buf = realloc(*buf, block_size*count);
|
|
||||||
if (new_buf == NULL) {
|
|
||||||
*buf = NULL;
|
|
||||||
return -1;
|
|
||||||
} else {
|
} else {
|
||||||
*buf = new_buf;
|
*ret = NULL;
|
||||||
}
|
}
|
||||||
}
|
return len;
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue