basic: nicer xsprintf and xstrftime assert messages
It's nicer if the assertion failure message from a bad use of xsprintf actually mentions xsprintf instead of the expression the macro is implemented as. The assert_message_se macro was added in the previous commit as an internal helper, but it can also be used for customizing assertion failure messages like in this case. Example: char buf[10]; xsprintf(buf, "This is a %s message.\n", "long"); Before: Assertion '(size_t) snprintf(buf, ELEMENTSOF(buf), "This is a %s message.\n", "long") < ELEMENTSOF(buf)' failed at foo.c:6, function main(). Aborting. After: Assertion 'xsprintf: buf[] must be big enough' failed at foo.c:6, function main(). Aborting.
This commit is contained in:
@@ -112,6 +112,8 @@ bool timezone_is_valid(const char *name);
|
||||
|
||||
clockid_t clock_boottime_or_monotonic(void);
|
||||
|
||||
#define xstrftime(buf, fmt, tm) assert_se(strftime(buf, ELEMENTSOF(buf), fmt, tm) > 0)
|
||||
#define xstrftime(buf, fmt, tm) \
|
||||
assert_message_se(strftime(buf, ELEMENTSOF(buf), fmt, tm) > 0, \
|
||||
"xstrftime: " #buf "[] must be big enough")
|
||||
|
||||
int get_timezone(char **timezone);
|
||||
|
||||
Reference in New Issue
Block a user