Update kmem_asprintf() and kmem_vasprintf() implementation

On a Linux system simply use the native aprintf and vasprintf
functions respectively.  Also update the call points to correctly
use va_copy() or va_start() as appropriate.
This commit is contained in:
Brian Behlendorf 2010-06-21 21:27:25 -07:00
parent 6107ded5d5
commit f9a7332118
3 changed files with 20 additions and 14 deletions

View File

@ -562,6 +562,7 @@ typedef struct callb_cpr {
#define zone_dataset_visible(x, y) (1)
#define INGLOBALZONE(z) (1)
extern char *kmem_vasprintf(const char *fmt, va_list adx);
extern char *kmem_asprintf(const char *fmt, ...);
#define strfree(str) kmem_free((str), strlen(str)+1)

View File

@ -1086,25 +1086,27 @@ ksiddomain_rele(ksiddomain_t *ksid)
umem_free(ksid, sizeof (ksiddomain_t));
}
/*
* Do not change the length of the returned string; it must be freed
* with strfree().
*/
char *
kmem_vasprintf(const char *fmt, va_list adx)
{
char *buf = NULL;
va_list adx_copy;
va_copy(adx_copy, adx);
VERIFY(vasprintf(&buf, fmt, adx_copy) != -1);
va_end(adx_copy);
return (buf);
}
char *
kmem_asprintf(const char *fmt, ...)
{
int size;
char *buf = NULL;
va_list adx;
char *buf;
va_start(adx, fmt);
size = vsnprintf(NULL, 0, fmt, adx) + 1;
va_end(adx);
buf = kmem_alloc(size, KM_SLEEP);
va_start(adx, fmt);
size = vsnprintf(buf, size, fmt, adx);
VERIFY(vasprintf(&buf, fmt, adx) != -1);
va_end(adx);
return (buf);

View File

@ -428,6 +428,7 @@ log_internal(history_internal_events_t event, spa_t *spa,
dmu_tx_t *tx, const char *fmt, va_list adx)
{
history_arg_t *ha;
va_list adx_copy;
/*
* If this is part of creating a pool, not everything is
@ -437,7 +438,9 @@ log_internal(history_internal_events_t event, spa_t *spa,
return;
ha = kmem_alloc(sizeof (history_arg_t), KM_SLEEP);
ha->ha_history_str = kmem_asprintf(fmt, adx);
va_copy(adx_copy, adx);
ha->ha_history_str = kmem_vasprintf(fmt, adx_copy);
va_end(adx_copy);
ha->ha_log_type = LOG_INTERNAL;
ha->ha_event = event;
ha->ha_zone = NULL;