]> git.ozlabs.org Git - ccan/blob - ccan/tal/stack/_info
Remove unused main() args in many modules.
[ccan] / ccan / tal / stack / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * tal/stack - stack of tal contextes (inspired by talloc_stack)
7  *
8  * Implement a stack of tal contexts. A new (empty) context is pushed on top
9  * of the stack using tal_newframe and it is popped/freed using tal_free().
10  * tal_curframe() can be used to get the stack's top context.
11  *
12  * tal_stack can be used to implement per-function temporary allocation context
13  * to help mitigating memory leaks, but unlike the plain tal approach it does not
14  * require the caller to pass a destination context for returning allocated
15  * values. Instead, allocated values are moved to the parent context using
16  * tal_steal(tal_parent(tmp_ctx), ptr).
17  *
18  * Example:
19  *      #include <assert.h>
20  *      #include <ccan/tal/stack/stack.h>
21  *
22  *      static int *do_work(void)
23  *      {
24  *              int *retval = NULL;
25  *              tal_t *tmp_ctx = tal_newframe();
26  *
27  *              int *val = talz(tmp_ctx, int);
28  *              assert(val != NULL);
29  *
30  *              // ... do something with val ...
31  *
32  *              if (retval >= 0) {
33  *                      // steal to parent cxt so it survives tal_free()
34  *                      tal_steal(tal_parent(tmp_ctx), val);
35  *                      retval = val;
36  *              }
37  *              tal_free(tmp_ctx);
38  *              return retval;
39  *      }
40  *
41  *      int main(void)
42  *      {
43  *              tal_t *tmp_ctx = tal_newframe();
44  *              int *val = do_work();
45  *              if (val) {
46  *                      // ... do something with val ...
47  *              }
48  *              // val is eventually freed
49  *              tal_free(tmp_ctx);
50  *              return 0;
51  *      }
52  *
53  * License: BSD-MIT
54  * Author: Delio Brignoli <brignoli.delio@gmail.com>
55  */
56 int main(int argc, char *argv[])
57 {
58         /* Expect exactly one argument */
59         if (argc != 2)
60                 return 1;
61
62         if (strcmp(argv[1], "depends") == 0) {
63                 printf("ccan/tal\n");
64                 return 0;
65         }
66
67         return 1;
68 }