#include <xtend/string.h>
-lxtend
size_t str_argv_cat(char *string, char *argv[], size_t first_arg,
size_t string_buff_size)
string String to which argv elements are appended
argv Character pointer array to a list of elements
first_arg Index of first argument to append
string_buff_size Size of string array including null byte
Append an argv style list of arguments to a string. This is useful for
constructing a command to be passed to a shell via system() or similar
methods.
Length of string + all argv elements. If this is greater than string_buff_size,
then the string has been truncated.
char cmd[CMD_MAX + 1] = "ls",
*argv[] = { "-l", NULL };
if ( str_argv_cat(cmd, argv, 0, CMD_MAX + 1) > CMD_MAX + 1 )
fputs("string is truncated.n", stderr);
else
system(cmd);
strlcpy(3), strlcat(3), snprintf(3)