vpac / src / alpm_log.h
30 lines · 25 sloc · 1.05 KB · 3609dfbd82867dc1034a443f8f9ced529ddbbedd
Raw
1// alpm_log.h is the C half of libalpm's log callback (ui.v holds the V
2// half). the callback takes a va_list, which V cannot receive portably —
3// a pointer on x86_64, a struct on aarch64 — so the line is formatted here,
4// with vsnprintf, and handed over whole. only ERROR and WARNING pass, the
5// levels pacman's cb_log prints by default: alpm_loglevel_t is bit flags
6#ifndef VPAC_ALPM_LOG_H
7#define VPAC_ALPM_LOG_H
8
9#include <stdarg.h>
10#include <stdio.h>
11#include <alpm.h>
12
13// vpac_log_line is exported by ui.v
14void vpac_log_line(void *ctx, int level, char *text);
15
16static void vpac_alpm_log(void *ctx, alpm_loglevel_t level, const char *fmt, va_list args) {
17 if(!(level & (ALPM_LOG_ERROR | ALPM_LOG_WARNING)) || fmt == NULL || fmt[0] == '\0') {
18 return;
19 }
20 char line[4096];
21 vsnprintf(line, sizeof line, fmt, args);
22 vpac_log_line(ctx, (int)level, line);
23}
24
25// vpac_set_alpm_log installs the callback, ctx being the run's TransUI
26static int vpac_set_alpm_log(alpm_handle_t *handle, void *ctx) {
27 return alpm_option_set_logcb(handle, vpac_alpm_log, ctx);
28}
29
30#endif
31