diff --git a/pdf.c b/pdf.c index 9c0e7023b0938c9dd89b756fb9412c775dc1605f..4c42ee4568528567b4c444438501ef4ad02e9459 100644 --- a/pdf.c +++ b/pdf.c @@ -48,9 +48,14 @@ log_entry **logs = NULL; void free_log_messages(); -void log_message(const char *message, uint8_t severity) +#include <stdarg.h> + +void log_message(uint8_t severity, const char *format, ...) { log_entry *msg; + char *final_string_buf = calloc(2048, sizeof(char)); + char *message; + va_list ap; if(logs_failed) { @@ -92,6 +97,20 @@ void log_message(const char *message, uint8_t severity) return; } + if(final_string_buf) + { + size_t msg_len; + + va_start(ap, format); + vsnprintf(final_string_buf, 2048, format, ap); + va_end(ap); + + msg_len = strlen(final_string_buf); + message = calloc(msg_len, sizeof(char)); + /* Due to calloc, last byte should be 0 at this point, so the string will be zero-terminated */ + strncpy(message, final_string_buf, msg_len-1); + } + msg = malloc(sizeof(log_message)); msg->message = message; msg->severity = severity;