[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v10 2/9] add function virCommandNewVAList



Add function virCommandNewVAList which is equivalent to the
virCommandNewArgList but with va_list instead of a variable number
of arguments.

Signed-off-by: Dmitry Guryanov <dguryanov parallels com>
---
 src/util/command.c |   22 ++++++++++++++++++++++
 src/util/command.h |    3 +++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/util/command.c b/src/util/command.c
index 35080d2..334ca89 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -815,6 +815,28 @@ virCommandNewArgList(const char *binary, ...)
     return cmd;
 }
 
+/**
+ * virCommandNewVAList:
+ * @binary: program to run
+ * @va_list: additional arguments
+ *
+ * Create a new command with a NULL terminated
+ * variable argument list.  @binary is handled as in virCommandNew.
+ */
+virCommandPtr
+virCommandNewVAList(const char *binary, va_list list)
+{
+    virCommandPtr cmd = virCommandNew(binary);
+    const char *arg;
+
+    if (!cmd || cmd->has_error)
+        return cmd;
+
+    while ((arg = va_arg(list, const char *)) != NULL)
+        virCommandAddArg(cmd, arg);
+    return cmd;
+}
+
 
 /*
  * Preserve the specified file descriptor in the child, instead of
diff --git a/src/util/command.h b/src/util/command.h
index 34d93a8..2eb460a 100644
--- a/src/util/command.h
+++ b/src/util/command.h
@@ -45,6 +45,9 @@ virCommandPtr virCommandNewArgs(const char *const*args) ATTRIBUTE_NONNULL(1);
 virCommandPtr virCommandNewArgList(const char *binary, ...)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
 
+virCommandPtr virCommandNewVAList(const char *binary, va_list list)
+    ATTRIBUTE_NONNULL(1);
+
 /* All error report from these setup APIs is
  * delayed until the Run/RunAsync methods
  */
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]