Commit 49b125f3 authored by Rusty Russell's avatar Rusty Russell

Fix examples (they all compile now), and init parent list in list

example.
parent 7beaa344
......@@ -16,7 +16,8 @@
*
* Example:
* #include <stdio.h>
* #include "alignof/alignof.h"
* #include <stdlib.h>
* #include <ccan/alignof/alignof.h>
*
* int main(int argc, char *argv[])
* {
......
......@@ -20,14 +20,17 @@
* #include <unistd.h>
* #include <sys/types.h>
* #include <err.h>
* #include "alloc/alloc.h"
* #include <sys/stat.h>
* #include <fcntl.h>
* #include <string.h>
* #include <ccan/alloc/alloc.h>
*
* static void usage(const char *name)
* {
* errx(1, "Usage: %s --create <mapfile>\n"
* " %s --check <mapfile>\n"
* " %s --alloc <mapfile>\n"
* " %s --free=<offset> <mapfile>\n", name, name, name);
* " %s --free=<offset> <mapfile>\n", name, name, name, name);
* }
*
* // Create a memory mapped file, and allocate from within it
......
......@@ -18,6 +18,14 @@
* you would catch such changes in your code like so:
*
* Example:
* #include <stddef.h>
* #include <ccan/build_assert/build_assert.h>
*
* struct foo {
* char string[5];
* int x;
* };
*
* char *foo_string(struct foo *foo)
* {
* // This trick requires that the string be first in the structure
......
......@@ -14,8 +14,14 @@
* callback.
*
* Example:
* struct info
* {
* #include <stdio.h>
* #include <ccan/container_of/container_of.h>
*
* struct timer {
* void *members;
* };
*
* struct info {
* int my_stuff;
* struct timer timer;
* };
......@@ -31,7 +37,9 @@
* struct info info = { .my_stuff = 1 };
*
* register_timer(&info.timer);
* ...
* // ...
* return 0;
* }
*
* Licence: LGPL (2 or any later version)
*/
......
......@@ -8,10 +8,11 @@
* This contains simple functions for getting the contents of a file.
*
* Example:
* #include "grab_file/grab_file.h"
* #include <err.h>
* #include <stdio.h>
* #include <string.h>
* #include <ccan/grab_file/grab_file.h>
* #include <ccan/talloc/talloc.h> // For talloc_free()
*
* int main(int argc, char *argv[])
* {
......
......@@ -12,7 +12,9 @@
*
* Example:
* #include <err.h>
* #include "list/list.h"
* #include <stdio.h>
* #include <stdlib.h>
* #include <ccan/list/list.h>
*
* struct parent {
* const char *name;
......@@ -35,7 +37,8 @@
* errx(1, "Usage: %s parent children...", argv[0]);
*
* p.name = argv[1];
* for (i = 2; i < argc, i++) {
* list_head_init(&p.children);
* for (i = 2; i < argc; i++) {
* c = malloc(sizeof(*c));
* c->name = argv[i];
* list_add(&p.children, &c->list);
......
......@@ -14,6 +14,10 @@
* #include <sys/types.h>
* #include <sys/stat.h>
* #include <fcntl.h>
* #include <stdbool.h>
* #include <string.h>
* #include <errno.h>
* #include <ccan/noerr/noerr.h>
*
* bool write_string_to_file(const char *file, const char *string)
* {
......
......@@ -9,7 +9,8 @@
* the standard string.h.
*
* Example:
* #include "str/str.h"
* #include <stdio.h>
* #include <ccan/str/str.h>
*
* int main(int argc, char *argv[])
* {
......
......@@ -10,9 +10,9 @@
* string utilities in "str.h".
*
* Example:
* #include "str_talloc/str_talloc.h"
* #include "talloc/talloc.h"
* #include "grab_file/grab_file.h"
* #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.
......
......@@ -31,9 +31,9 @@
* #include <stdio.h>
* #include <stdarg.h>
* #include <err.h>
* #include "talloc/talloc.h"
* #include <ccan/talloc/talloc.h>
*
* // A structure containing a popened comman.
* // A structure containing a popened command.
* struct command
* {
* FILE *f;
......@@ -79,7 +79,7 @@
* struct command *cmd;
*
* if (argc != 2)
* errx(1, "Usage: %s <command>\n");
* errx(1, "Usage: %s <command>\n", argv[0]);
*
* cmd = open_output_cmd(NULL, "%s hello", argv[1]);
* if (!cmd)
......
......@@ -20,7 +20,7 @@
*
* Example:
* #include <string.h>
* #include "tap/tap.h"
* #include <ccan/tap/tap.h>
*
* // Run some simple (but overly chatty) tests on strcmp().
* int main(int argc, char *argv[])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment