diff options
Diffstat (limited to 'src/c_wayland_client.c')
-rw-r--r-- | src/c_wayland_client.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/c_wayland_client.c b/src/c_wayland_client.c new file mode 100644 index 0000000..bdd62e6 --- /dev/null +++ b/src/c_wayland_client.c @@ -0,0 +1,45 @@ + + +#include <stdio.h> +#include <wayland-client-core.h> +#include "c_wayland_client.h" + + +log_hook_t ada_handler; +char buf[256]; + + +void actual_log_handler(const char *c, va_list va) { + char *str = buf; + char *extra = NULL; + int len; + + if (c == NULL) { + (*ada_handler)(c,0); + return; + } + + len = vsnprintf(str, 256, c, va); + if (len >= 256) { + extra = malloc((len + 1) * sizeof(char)); + if (extra == NULL) { + (*ada_handler)(extra,1); + return; + } + str = extra; + vsnprintf(str, len + 1, c, va); + } + + (*ada_handler)(str,0); + + if (extra != NULL) { + free(extra); + } +} + + +void wayland_client_set_log_hook(log_hook_t func) { + ada_handler = func; + wl_log_set_handler_client(&actual_log_handler); +} + |