diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-02-22 14:59:32 +1030 |
---|---|---|
committer | Amitay Isaacs <amitay@gmail.com> | 2012-03-07 13:16:16 +1100 |
commit | 361f3ea9ee577c5a3e2fed687a0b417b257c31de (patch) | |
tree | 6d356c3aa64317c609ff4e208be76e18996a55f8 /lib/ccan/tcon/_info | |
parent | 4f5412dda687c3ff76b426842bf284d01d56a997 (diff) | |
download | samba-361f3ea9ee577c5a3e2fed687a0b417b257c31de.tar.gz samba-361f3ea9ee577c5a3e2fed687a0b417b257c31de.tar.bz2 samba-361f3ea9ee577c5a3e2fed687a0b417b257c31de.zip |
lib/ccan: import failtest and required ccan modules for TDB2 unit tests.
New modules: failtest, list, time, read_write_all and tlist.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ccan/tcon/_info')
-rw-r--r-- | lib/ccan/tcon/_info | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/ccan/tcon/_info b/lib/ccan/tcon/_info new file mode 100644 index 0000000000..02c0dd8add --- /dev/null +++ b/lib/ccan/tcon/_info @@ -0,0 +1,74 @@ +#include "config.h" +#include <string.h> + +/** + * tcon - routines for creating typesafe generic containers + * + * This code lets users create a structure with a typecanary; your API + * is then a set of macros which check the type canary before calling + * the generic routines. + * + * Example: + * #include <ccan/tcon/tcon.h> + * #include <stdio.h> + * + * // A simple container class. Can only contain one thing though! + * struct container { + * void *contents; + * }; + * static inline void container_add_raw(struct container *c, void *p) + * { + * c->contents = p; + * } + * static inline void *container_get_raw(struct container *c) + * { + * return c->contents; + * } + * + * // This lets the user define their container type; includes a + * // "type canary" to check types against. + * #define DEFINE_TYPED_CONTAINER_STRUCT(name, type) \ + * struct name { struct container raw; TCON(type canary); } + * + * // These macros make sure the container type and pointer match. + * #define container_add(c, p) \ + * container_add_raw(&tcon_check((c), canary, (p))->raw, (p)) + * #define container_get(c) \ + * tcon_cast((c), canary, container_get_raw(&(c)->raw)) + * + * // Now, let's define two different containers. + * DEFINE_TYPED_CONTAINER_STRUCT(int_container, int *); + * DEFINE_TYPED_CONTAINER_STRUCT(string_container, char *); + * + * int main(int argc, char *argv[]) + * { + * struct int_container ic; + * struct string_container sc; + * + * // We would get a warning if we used the wrong types... + * container_add(&ic, &argc); + * container_add(&sc, argv[argc-1]); + * + * printf("Last arg is %s of %i arguments\n", + * container_get(&sc), *container_get(&ic) - 1); + * return 0; + * } + * // Given "foo" outputs "Last arg is foo of 1 arguments" + * // Given "foo bar" outputs "Last arg is bar of 2 arguments" + * + * License: Public domain + * + * Author: Rusty Russell <rusty@rustcorp.com.au> + */ +int main(int argc, char *argv[]) +{ + /* Expect exactly one argument */ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + return 0; + } + + return 1; +} |