refactor: standardize error reporting on the log module
- Add log_perror() helper (context + strerror(errno)) to the log module - Replace all bare perror() calls with log_perror() so errors are routed through the unified logger (stderr sink + optional --log-file sink) - Convert fprintf(stderr, "Error:/Warning: ...") in client code to log_message(); raw fprintf kept only for progress/stats output
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "log.h"
|
||||
#include "array_list.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -6,7 +7,7 @@
|
||||
ArrayList* array_list_create(void (*item_destroyer)(void* item)) {
|
||||
ArrayList* list = (ArrayList*)malloc(sizeof(ArrayList));
|
||||
if (list == NULL) {
|
||||
perror("ERROR: Could not allocate memory for array list struct");
|
||||
log_perror("ERROR: Could not allocate memory for array list struct");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -42,7 +43,7 @@ static bool array_list_extend(ArrayList* array_list) {
|
||||
new_capacity = INITIAL_ARRAY_SIZE;
|
||||
void* new_items = realloc(array_list->items, new_capacity * sizeof(void*));
|
||||
if (new_items == NULL) {
|
||||
perror("ERROR: Could not reallocate memory for array list items");
|
||||
log_perror("ERROR: Could not reallocate memory for array list items");
|
||||
return false;
|
||||
}
|
||||
array_list->items = new_items;
|
||||
@@ -68,7 +69,7 @@ void** array_list_to_array(const ArrayList* array_list) {
|
||||
}
|
||||
void** array = malloc(array_list->size * sizeof(void*));
|
||||
if (array == NULL) {
|
||||
perror("Could not malloc space for array from array list!");
|
||||
log_perror("Could not malloc space for array from array list!");
|
||||
return NULL;
|
||||
}
|
||||
memcpy(array, array_list->items, array_list->size * sizeof(void*));
|
||||
|
||||
Reference in New Issue
Block a user