]> git.ozlabs.org Git - ccan/blob - ccan/take/_info
ccanlint: enhance and streamline "output" testing lines.
[ccan] / ccan / take / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * take - routines to mark pointers to be consumed by called functions.
7  *
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.
11  *
12  * Author: Rusty Russell <rusty@rustcorp.com.au>
13  * License: CC0 (Public domain)
14  *
15  * Example:
16  *      // Given "foo/bar.c" outputs basename is bar.c
17  *      #include <ccan/take/take.h>
18  *      #include <string.h>
19  *
20  *      // Dumb basename program and driver.
21  *      static char *base(const char *file)
22  *      {
23  *              const char *p = strrchr(file, '/');
24  *              if (!p) 
25  *                      p = file;
26  *              else
27  *                      p++;
28  *
29  *              // Use arg in place if we're allowed.
30  *              if (taken(file))
31  *                      return memmove((char *)file, p, strlen(p)+1);
32  *              else
33  *                      return strdup(p);
34  *      }
35  *
36  *      int main(int argc, char *argv[])
37  *      {
38  *              char *b;
39  *
40  *              if (argv[1]) // Mangle in place.
41  *                      b = base(take(argv[1]));
42  *              else
43  *                      b = base("test/string");
44  *
45  *              printf("basename is %s\n", b);
46  *              return 0;
47  *      }
48  */
49 int main(int argc, char *argv[])
50 {
51         if (argc != 2)
52                 return 1;
53
54         if (strcmp(argv[1], "depends") == 0) {
55                 printf("ccan/likely\n");
56                 return 0;
57         }
58
59         return 1;
60 }