yay/vendor/github.com/jguer/go-alpm/callbacks.c

40 lines
945 B
C
Raw Normal View History

2017-07-14 19:03:54 +02:00
// callbacks.c - Sets alpm callbacks to Go functions.
//
// Copyright (c) 2013 The go-alpm Authors
//
// MIT Licensed. See LICENSE for details.
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <alpm.h>
void logCallback(uint16_t level, char *cstring);
2018-03-16 21:54:28 +01:00
void questionCallback(alpm_question_t *question);
2017-07-14 19:03:54 +02:00
void go_alpm_log_cb(alpm_loglevel_t level, const char *fmt, va_list arg) {
char *s = malloc(128);
if (s == NULL) return;
int16_t length = vsnprintf(s, 128, fmt, arg);
if (length > 128) {
length = (length + 16) & ~0xf;
s = realloc(s, length);
}
if (s != NULL) {
logCallback(level, s);
free(s);
}
}
2018-03-16 21:54:28 +01:00
void go_alpm_question_cb(alpm_question_t *question) {
questionCallback(question);
}
2017-07-14 19:03:54 +02:00
void go_alpm_set_logging(alpm_handle_t *handle) {
2018-03-16 21:54:28 +01:00
alpm_option_set_logcb(handle, go_alpm_log_cb);
2017-07-14 19:03:54 +02:00
}
2018-03-16 21:54:28 +01:00
void go_alpm_set_question(alpm_handle_t *handle) {
alpm_option_set_questioncb(handle, go_alpm_question_cb);
}