From 729780d3f6d244faacfa95c2935888d83ca6006f Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Tue, 11 Jan 2022 03:21:46 +0800 Subject: [PATCH] [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. --- src/lib/platform/exit_code.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lib/platform/exit_code.h b/src/lib/platform/exit_code.h index 81a332128..ccb8f7c66 100644 --- a/src/lib/platform/exit_code.h +++ b/src/lib/platform/exit_code.h @@ -36,6 +36,7 @@ #include #include +#include #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) /**