18.2.225. PMIx_Argv_join

PMIx_Argv_join — Concatenate the entries of a NULL-terminated argv-style array into a single newly allocated string.

18.2.225.1. SYNOPSIS

#include <pmix.h>

char *PMIx_Argv_join(char **argv, int delimiter);

18.2.225.1.1. Python Syntax

No Python equivalent

18.2.225.2. INPUT PARAMETERS

  • argv: Pointer to a NULL-terminated argv-style array, or NULL.

  • delimiter: The character inserted between successive entries, passed as an int and stored as a single char.

18.2.225.3. DESCRIPTION

Join every entry of argv into one freshly allocated string, placing a single delimiter character between each pair of adjacent entries. No delimiter is added before the first entry or after the last, and the result is NUL-terminated.

This is the inverse of the split routines: joining with a given delimiter and splitting the result on that same delimiter round-trips an array that contains no embedded delimiter characters and no empty entries.

The returned string is owned by the caller and must be released with free.

18.2.225.4. RETURN VALUE

Returns a newly allocated, NUL-terminated string. If argv is NULL or its first element is NULL (an empty array), a newly allocated empty string ("") is returned rather than NULL. NULL is returned only if the allocation of the result string fails.

18.2.225.5. NOTES

Because a non-NULL result is always returned for the empty-array case, the caller must still free the returned pointer in that case. The returned string is an ordinary heap allocation — free it with free, not with PMIx_Argv_free(3), which is for arrays.

18.2.225.6. EXAMPLES

char **argv = PMIx_Argv_split("a:b:c", ':');
char  *str  = PMIx_Argv_join(argv, '/');
/* str == "a/b/c" */

free(str);
PMIx_Argv_free(argv);