Commit f35cc512 authored by Philipp Schafft's avatar Philipp Schafft 🦁
Browse files

Feature: Added log_contents_array() as a nicer version of log_contents()

parent 819fcac1
......@@ -439,6 +439,39 @@ void log_contents (int log_id, char **_contents, unsigned int *_len)
_unlock_logger ();
}
char ** log_contents_array(int log_id)
{
log_entry_t *entry;
char **ret;
size_t i;
if (log_id < 0) return NULL;
if (log_id >= LOG_MAXLOGS) return NULL; /* Bad log number */
_lock_logger();
ret = calloc(loglist[log_id].entries + 1, sizeof(char*));
if (!ret) {
_unlock_logger();
return NULL;
}
i = 0;
entry = loglist[log_id].log_head;
while (entry) {
ret[i] = malloc(entry->len);
memcpy(ret[i], entry->line, entry->len);
if (ret[i][entry->len-2] == '\n')
ret[i][entry->len-2] = 0;
entry = entry->next;
i++;
}
ret[i] = NULL;
_unlock_logger();
return ret;
}
static inline int __vsnprintf__is_print(int c, int allow_space)
{
if ((c <= '"' || c == '`' || c == '\\') && !(allow_space && c == ' ')) {
......
......@@ -52,6 +52,7 @@ void log_set_trigger(int id, unsigned trigger);
int log_set_filename(int id, const char *filename);
void log_set_lines_kept (int log_id, unsigned int count);
void log_contents (int log_id, char **_contents, unsigned int *_len);
char ** log_contents_array(int log_id);
int log_set_archive_timestamp(int id, int value);
void log_flush(int log_id);
void log_reopen(int log_id);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment