Browse Source Download (without any required ccan dependencies)

Module:

stringbuilder

Summary:

join lists of strings

Author:

Stuart Longland <stuartl@longlandclan.yi.org>

Description:

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.

Example:

#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;
}

License:

CC0 (Public domain)