diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index 02bf421b4..0786b3815 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -1291,6 +1291,7 @@ int dm_fclose(FILE *stream); */ int dm_asprintf(char **buf, const char *format, ...) __attribute__ ((format(printf, 2, 3))); +int dm_vasprintf(char **buf, const char *format, va_list ap); /* * create lockfile (pidfile) - create and lock a lock file diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c index 776ec97e6..5ef633435 100644 --- a/libdm/libdm-string.c +++ b/libdm/libdm-string.c @@ -129,7 +129,7 @@ const char *dm_basename(const char *path) return p ? p + 1 : path; } -int dm_asprintf(char **result, const char *format, ...) +int dm_vasprintf(char **result, const char *format, va_list aq) { int i, n, size = 16; va_list ap; @@ -141,7 +141,7 @@ int dm_asprintf(char **result, const char *format, ...) return -1; for (i = 0;; i++) { - va_start(ap, format); + va_copy(ap, aq); n = vsnprintf(buf, size, format, ap); va_end(ap); @@ -168,6 +168,16 @@ int dm_asprintf(char **result, const char *format, ...) return n + 1; } +int dm_asprintf(char **result, const char *format, ...) +{ + int r; + va_list ap; + va_start(ap, format); + r = dm_vasprintf(result, format, ap); + va_end(ap); + return r; +} + /* * Count occurences of 'c' in 'str' until we reach a null char. *