X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fptrint%2F_info;fp=ccan%2Fptrint%2F_info;h=8135d1ee8ee4a90cbb94189f6f0f2fafc2dd9bcf;hb=53079b9c300f1bdf1cd5695a13f3ccbe2de86ee9;hp=0000000000000000000000000000000000000000;hpb=9d4ae5f1313a25c99cd5b909ee1038e4424b46cb;p=ccan diff --git a/ccan/ptrint/_info b/ccan/ptrint/_info new file mode 100644 index 00000000..8135d1ee --- /dev/null +++ b/ccan/ptrint/_info @@ -0,0 +1,59 @@ +#include "config.h" +#include +#include + +/** + * ptrint - Encoding integers in pointer values + * + * Library (standard or ccan) functions which take user supplied + * callbacks usually have the callback supplied with a void * context + * pointer. For simple cases, it's sometimes sufficient to pass a + * simple integer cast into a void *, rather than having to allocate a + * context structure. This module provides some helper macros to do + * this relatively safely and portably. + * + * The key characteristics of these functions are: + * ptr2int(int2ptr(val)) == val + * and + * !int2ptr(val) == !val + * (i.e. the transformation preserves truth value). + * + * Example: + * #include + * + * static void callback(void *opaque) + * { + * int val = ptr2int(opaque); + * printf("Value is %d\n", val); + * } + * + * void (*cb)(void *opaque) = callback; + * + * int main(int argc, char *argv[]) + * { + * int val = 17; + * + * (*cb)(int2ptr(val)); + * exit(0); + * } + * + * License: CC0 (Public domain) + * Author: David Gibson + */ +int main(int argc, char *argv[]) +{ + /* Expect exactly one argument */ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + printf("ccan/build_assert\n"); + return 0; + } + if (strcmp(argv[1], "testdepends") == 0) { + printf("ccan/array_size\n"); + return 0; + } + + return 1; +}