5 * take - routines to mark pointers to be consumed by called functions.
7 * This code helps to implement ownership transfer on a per-arg basis:
8 * the caller wraps the pointer argument in take() and the callee checks
9 * taken() to see if it should consume it.
11 * Author: Rusty Russell <rusty@rustcorp.com.au>
12 * License: CC0 (Public domain)
15 * // Given foo/bar.c outputs basename is bar.c
16 * #include <ccan/take/take.h>
19 * // Dumb basename program and driver.
20 * static char *base(const char *file)
22 * const char *p = strrchr(file, '/');
28 * // Use arg in place if we're allowed.
30 * return memmove((char *)file, p, strlen(p)+1);
35 * int main(int argc, char *argv[])
39 * if (argv[1]) // Mangle in place.
40 * b = base(take(argv[1]));
42 * b = base("test/string");
44 * printf("basename is %s\n", b);
48 int main(int argc, char *argv[])
53 if (strcmp(argv[1], "depends") == 0) {
54 printf("ccan/likely\n");