Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions include/libbase/log_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ static inline void *_logged_malloc(
#define logged_malloc(size) \
_logged_malloc(__FILE__, __LINE__, size)

/** Helper: Calls strdup(3) and logs errors for given file & line. */
/** Helper: Acts like strdup(3) and logs errors for given file & line. */
static inline char *_logged_strdup(
const char *filename_ptr, int line_no, const char *str)
{
char *new_str = strdup(str);
if ((NULL == new_str) && (BS_ERROR >= bs_log_severity)) {
size_t len = strlen(str) + 1;
char *new_str = malloc(len);
if (NULL != new_str) {
memcpy(new_str, str, len);
} else if (BS_ERROR >= bs_log_severity) {
bs_log_write((bs_log_severity_t)(BS_ERROR | BS_ERRNO), filename_ptr,
line_no, "Failed strdup(%s)", str);
}
Expand Down