Comprehensive C Archive Network

Upload Code Download Code About

Browse Source Download (without any required ccan dependencies)

Module:

str_talloc

Summary:

string helper routines which use talloc

Author:

Rusty Russell <rusty@rustcorp.com.au>

Dependencies:

 ccan/str ccan/talloc ccan/noerr  

Description:

This is a grab bag of fnctions for string operations, designed to enhance the standard string.h; these are separated from the non-talloc-needing string utilities in "str.h".

Example:

#include <ccan/str_talloc/str_talloc.h>
#include <ccan/talloc/talloc.h>
#include <ccan/grab_file/grab_file.h>
#include <err.h>

// Dumb demo program to double-linespace a file.
int main(int argc, char *argv[])
{
        char *textfile;
        char **lines;

        // Grab lines in file.
        textfile = grab_file(NULL, argv[1], NULL);
        if (!textfile)
                err(1, "Failed reading %s", argv[1]);
        lines = strsplit(textfile, textfile, "\n");

        // Join them back together with two linefeeds.
        printf("%s", strjoin(textfile, lines, "\n\n"));

        // Free everything, just because we can.
        talloc_free(textfile);
        return 0;
}

License:

LGPL (v2.1 or any later version)