added custom define for macro `__FILE_NAME__` for non supporting compilers

This commit is contained in:
Sven Vogel 2024-04-14 17:09:28 +02:00
parent 8bd4898440
commit 2b46c9e3ab
1 changed files with 11 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include <stdio.h>
#include <sys/cdefs.h>
#include <string.h>
#define LOG_DEFAULT_STREAM stderr
@ -20,6 +21,16 @@
#define LOG_STRING_INFORMATION "Information"
#define LOG_STRING_DEBUG "Debug"
// define __FILE_NAME__ macro if not defined
// generally not defined by GCC < 11.3 and MSVC
#ifndef __FILE_NAME__
#if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)
#define __FILE_NAME__ (strrstr(__FILE__, "\\\\") ? strrstr(__FILE__, "\\\\") + 1 : __FILE__)
#else
#define __FILE_NAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
#endif
/**
* @brief Panic is used in cases where the process is in an unrecoverable state.
* This macro will print debug information to stderr and call abort() to