1
0
Fork 0

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

This commit is contained in:
Philipp Schafft 2020-10-02 09:42:16 +00:00
parent 819fcac1b1
commit f35cc512b4
2 changed files with 34 additions and 0 deletions

View File

@ -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 == ' ')) {

View File

@ -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);