Bring the add_sprintf function for stringsbuf from the library.
---
daemon/daemon.h | 2 ++
daemon/guestfsd.c | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 0caad45..705aa95 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -89,6 +89,8 @@ struct stringsbuf {
*/
extern int add_string_nodup (struct stringsbuf *sb, char *str);
extern int add_string (struct stringsbuf *sb, const char *str);
+extern int add_sprintf (struct stringsbuf *sb, const char *fs, ...)
+ __attribute__((format (printf,2,3)));
extern int end_stringsbuf (struct stringsbuf *sb);
extern size_t count_strings (char *const *argv);
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 0a59c84..321544f 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -560,6 +560,26 @@ add_string (struct stringsbuf *sb, const char *str)
}
int
+add_sprintf (struct stringsbuf *sb, const char *fs, ...)
+{
+ va_list args;
+ char *str;
+ int r;
+
+ va_start (args, fs);
+ r = vasprintf (&str, fs, args);
+ va_end (args);
+ if (r == -1) {
+ reply_with_perror ("vasprintf");
+ free_stringslen (sb->argv, sb->size);
+ sb->argv = NULL;
+ return -1;
+ }
+
+ return add_string_nodup (sb, str);
+}
+
+int
end_stringsbuf (struct stringsbuf *sb)
{
return add_string_nodup (sb, NULL);
--
1.9.3