Browse Source Download (without any required ccan dependencies)
stringbuilder
join lists of strings
Stuart Longland <[email protected]>
This is a small set of functions for building up strings from a list. The destination buffer is bounds-checked, the functions return failure if the concatenated strings overflow the buffer.
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ccan/stringbuilder/stringbuilder.h>
int main(int argc, char *argv[])
{
char mystring[128];
int res;
res = stringbuilder_array(mystring, 128, "', '",
argc, (const char**)argv);
if (!res)
printf("My arguments: '%s'\n", mystring);
else
printf("Failed to join arguments: %s\n",
strerror(res));
if (!res) {
res = stringbuilder(mystring, 128, ", ",
"This", "Is", "A", "Test");
if (!res)
printf("My string: '%s'\n", mystring);
else
printf("Failed to join strings: %s\n",
strerror(res));
}
return 0;
}
CC0 (Public domain)