Add argvJoin() for combining an argv array into a string

This commit is contained in:
Panu Matilainen 2008-04-18 12:36:02 +03:00
parent 8058de50b2
commit 2c0f7b54ad
2 changed files with 20 additions and 0 deletions

View File

@ -197,3 +197,15 @@ int argvSplit(ARGV_t * argvp, const char * str, const char * seps)
*argvp = argv; *argvp = argv;
return 0; return 0;
} }
char *argvJoin(ARGV_const_t argv, const char *sep)
{
char *dest = NULL;
char * const *arg;
for (arg = argv; *arg; arg++) {
rstrscat(&dest, *arg, *(arg+1) ? sep : "", NULL);
}
return dest;
}

View File

@ -147,6 +147,14 @@ int argvAppend(ARGV_t * argvp, ARGV_const_t av);
*/ */
int argvSplit(ARGV_t * argvp, const char * str, const char * seps); int argvSplit(ARGV_t * argvp, const char * str, const char * seps);
/** \ingroup rpmargv
* Join an argv array into a string.
* @param *argv argv array to join
* @param sep seperator string to use
* @return malloc'ed string
*/
char *argvJoin(ARGV_const_t argv, const char *sep);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif