Skip to content

Commit 8d9b33e

Browse files
committed
Compile time __FILENAME__ extraction
1 parent 23dc73b commit 8d9b33e

File tree

1 file changed

+14
-1
lines changed
  • core/include/tangram

1 file changed

+14
-1
lines changed

core/include/tangram/log.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@
1515
* LOGS: Screen log, no LOG_LEVEL
1616
*/
1717

18-
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
18+
//#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
19+
// From: https://blog.galowicz.de/2016/02/20/short_file_macro/
20+
static constexpr const char * past_last_slash(const char * const str, const char * const last_slash) {
21+
return *str == '\0' ? last_slash :
22+
*str == '/' ? past_last_slash(str + 1, str + 1) :
23+
past_last_slash(str + 1, last_slash);
24+
}
25+
26+
static constexpr const char * past_last_slash(const char * const str) {
27+
return past_last_slash(str, str);
28+
}
29+
30+
#define __FILENAME__ ({constexpr const char * const sf__ {past_last_slash(__FILE__)}; sf__;})
31+
1932
#define TANGRAM_MAX_BUFFER_LOG_SIZE 99999
2033

2134
#if LOG_LEVEL >= 3

0 commit comments

Comments
 (0)