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

[libvirt] [PATCH 1/3]: Move argvToString to util



The attached patch moves the argvToString function
from iptables.c to util.c for use in later patches.

Thanks,
Cole

commit c115b34455789910597061c7b100e056cb3fe787
Author: Cole Robinson <crobinso redhat com>
Date:   Fri Oct 24 10:10:11 2008 -0400

    Move argvToString to virArgvToString in util

diff --git a/src/iptables.c b/src/iptables.c
index 726141a..53e0f41 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -384,32 +384,6 @@ iptRulesNew(const char *table,
     return NULL;
 }
 
-static char *
-argvToString(const char *const *argv)
-{
-    int len, i;
-    char *ret, *p;
-
-    for (len = 1, i = 0; argv[i]; i++)
-        len += strlen(argv[i]) + 1;
-
-    if (VIR_ALLOC_N(ret, len) < 0)
-        return NULL;
-    p = ret;
-
-    for (i = 0; argv[i]; i++) {
-        if (i != 0)
-            *(p++) = ' ';
-
-        strcpy(p, argv[i]);
-        p += strlen(argv[i]);
-    }
-
-    *p = '\0';
-
-    return ret;
-}
-
 static int
 iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
 {
@@ -464,7 +438,7 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
 
     va_end(args);
 
-    if (!(rule = argvToString(&argv[command_idx])))
+    if (!(rule = virArgvToString(&argv[command_idx])))
         goto error;
 
     if (action == REMOVE) {
diff --git a/src/util.c b/src/util.c
index aa21653..4476323 100644
--- a/src/util.c
+++ b/src/util.c
@@ -87,6 +87,33 @@ int virFileStripSuffix(char *str,
     return 1;
 }
 
+char *
+virArgvToString(const char *const *argv)
+{
+    int len, i;
+    char *ret, *p;
+
+    for (len = 1, i = 0; argv[i]; i++)
+        len += strlen(argv[i]) + 1;
+
+    if (VIR_ALLOC_N(ret, len) < 0)
+        return NULL;
+    p = ret;
+
+    for (i = 0; argv[i]; i++) {
+        if (i != 0)
+            *(p++) = ' ';
+
+        strcpy(p, argv[i]);
+        p += strlen(argv[i]);
+    }
+
+    *p = '\0';
+
+    return ret;
+}
+
+
 #ifndef __MINGW32__
 
 static int virSetCloseExec(int fd) {
diff --git a/src/util.h b/src/util.h
index 093ef46..8e91dd7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -87,6 +87,8 @@ int virFileReadPid(const char *dir,
 int virFileDeletePid(const char *dir,
                      const char *name);
 
+char *virArgvToString(const char *const *argv);
+
 int __virStrToLong_i(char const *s,
                      char **end_ptr,
                      int base,

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