diff options
| author | christos <christos@NetBSD.org> | 2020-05-24 19:26:37 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2020-05-24 19:26:37 +0000 |
| commit | fbb2e0a3dd96bbc9a8cffc7c8ac4aac2544fc387 (patch) | |
| tree | 46a13ac82242577d9063d930f5867da58f5cbc17 /external/mit/libuv/dist/docs/code/plugin | |
| parent | 55efb4b237a9518e5e60aefded844c0066850759 (diff) | |
Import libuv, needed by bind-9.16.x
Diffstat (limited to 'external/mit/libuv/dist/docs/code/plugin')
| -rw-r--r-- | external/mit/libuv/dist/docs/code/plugin/hello.c | 5 | ||||
| -rw-r--r-- | external/mit/libuv/dist/docs/code/plugin/main.c | 39 | ||||
| -rw-r--r-- | external/mit/libuv/dist/docs/code/plugin/plugin.h | 7 |
3 files changed, 51 insertions, 0 deletions
diff --git a/external/mit/libuv/dist/docs/code/plugin/hello.c b/external/mit/libuv/dist/docs/code/plugin/hello.c new file mode 100644 index 00000000000..7b2861d7dde --- /dev/null +++ b/external/mit/libuv/dist/docs/code/plugin/hello.c @@ -0,0 +1,5 @@ +#include "plugin.h" + +void initialize() { + mfp_register("Hello World!"); +} diff --git a/external/mit/libuv/dist/docs/code/plugin/main.c b/external/mit/libuv/dist/docs/code/plugin/main.c new file mode 100644 index 00000000000..06e581e63db --- /dev/null +++ b/external/mit/libuv/dist/docs/code/plugin/main.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include <uv.h> + +#include "plugin.h" + +typedef void (*init_plugin_function)(); + +void mfp_register(const char *name) { + fprintf(stderr, "Registered plugin \"%s\"\n", name); +} + +int main(int argc, char **argv) { + if (argc == 1) { + fprintf(stderr, "Usage: %s [plugin1] [plugin2] ...\n", argv[0]); + return 0; + } + + uv_lib_t *lib = (uv_lib_t*) malloc(sizeof(uv_lib_t)); + while (--argc) { + fprintf(stderr, "Loading %s\n", argv[argc]); + if (uv_dlopen(argv[argc], lib)) { + fprintf(stderr, "Error: %s\n", uv_dlerror(lib)); + continue; + } + + init_plugin_function init_plugin; + if (uv_dlsym(lib, "initialize", (void **) &init_plugin)) { + fprintf(stderr, "dlsym error: %s\n", uv_dlerror(lib)); + continue; + } + + init_plugin(); + } + + return 0; +} diff --git a/external/mit/libuv/dist/docs/code/plugin/plugin.h b/external/mit/libuv/dist/docs/code/plugin/plugin.h new file mode 100644 index 00000000000..21f194e670e --- /dev/null +++ b/external/mit/libuv/dist/docs/code/plugin/plugin.h @@ -0,0 +1,7 @@ +#ifndef UVBOOK_PLUGIN_SYSTEM +#define UVBOOK_PLUGIN_SYSTEM + +// Plugin authors should use this to register their plugins with mfp. +void mfp_register(const char *name); + +#endif |
