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