1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

libdm-string: Add dm_vasprintf.

This commit is contained in:
Petr Rockai 2012-07-30 16:41:15 +02:00
parent 88ae884095
commit e0c2211c34
2 changed files with 13 additions and 2 deletions

View File

@ -1291,6 +1291,7 @@ int dm_fclose(FILE *stream);
*/ */
int dm_asprintf(char **buf, const char *format, ...) int dm_asprintf(char **buf, const char *format, ...)
__attribute__ ((format(printf, 2, 3))); __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 * create lockfile (pidfile) - create and lock a lock file

View File

@ -129,7 +129,7 @@ const char *dm_basename(const char *path)
return p ? p + 1 : 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; int i, n, size = 16;
va_list ap; va_list ap;
@ -141,7 +141,7 @@ int dm_asprintf(char **result, const char *format, ...)
return -1; return -1;
for (i = 0;; i++) { for (i = 0;; i++) {
va_start(ap, format); va_copy(ap, aq);
n = vsnprintf(buf, size, format, ap); n = vsnprintf(buf, size, format, ap);
va_end(ap); va_end(ap);
@ -168,6 +168,16 @@ int dm_asprintf(char **result, const char *format, ...)
return n + 1; 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. * Count occurences of 'c' in 'str' until we reach a null char.
* *