summaryrefslogtreecommitdiff
path: root/src/c_wayland_client.c
blob: bdd62e69cc42f3e3df32c00efdf0f7f8dba0c848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);
}