diff --git a/ChangeLog b/ChangeLog index 723fcafdf2fad5abc2d3e1e037b6aad31a9e6e13..c268d90f6da260253530a7d8000701aaf464f08b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Nov 5 13:19:00 EST 2008 Cole Robinson + + * src/iptables.c, src/util.c, src/util.h: Move local argvToString to + virArgvToString. + Wed Nov 5 15:22:12 CET 2008 Jim Meyering plug two leaks and fix a diagnostic diff --git a/src/iptables.c b/src/iptables.c index 726141a88f029791493a51954416fe447b7f87ca..53e0f4130e91b2b069fd14e4d730dc0feb26eb87 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 a750100c21bfc0c251ca8296fcd5c52cd06339a9..61ad6033a9df9d3b363809d7bdbdc6fa0a13d7bb 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 689da602076da1ca05c7f86a3e232c8f062a0280..21e9ad3545457c2afb3c7f48310c4bdcd3178729 100644 --- a/src/util.h +++ b/src/util.h @@ -88,6 +88,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,