[logging] print basename of source file (#7295)

In some build systems, source files is passed as absolute path, log
messages may be truncated. This commit makes VerifyOrDie only prints
basename of the source file.
This commit is contained in:
Yakun Xu
2022-01-10 11:21:46 -08:00
committed by GitHub
parent b69aac4aa8
commit 729780d3f6
+12 -8
View File
@@ -36,6 +36,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
@@ -101,14 +102,17 @@ const char *otExitCodeToString(uint8_t aExitCode);
* @param[in] aExitCode The exit code.
*
*/
#define VerifyOrDie(aCondition, aExitCode) \
do \
{ \
if (!(aCondition)) \
{ \
otLogCritPlat("%s() at %s:%d: %s", __func__, __FILE__, __LINE__, otExitCodeToString(aExitCode)); \
exit(aExitCode); \
} \
#define VerifyOrDie(aCondition, aExitCode) \
do \
{ \
if (!(aCondition)) \
{ \
const char *start = strrchr(__FILE__, '/'); \
OT_UNUSED_VARIABLE(start); \
otLogCritPlat("%s() at %s:%d: %s", __func__, (start ? start + 1 : __FILE__), __LINE__, \
otExitCodeToString(aExitCode)); \
exit(aExitCode); \
} \
} while (false)
/**