]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/basic/util.h
basic: nicer xsprintf and xstrftime assert messages 1278/head
authorMichal Schmidt <mschmidt@redhat.com>
Mon, 14 Sep 2015 13:53:47 +0000 (15:53 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Wed, 16 Sep 2015 13:48:00 +0000 (15:48 +0200)
commita8b626100b88b50c6c73fccf81b278d64e7e25a2
tree7c1e487c66797d6a73c1a0cc55a73294896489e5
parent34c38d2aaa2535cb40d0157b0e4a84e6be72ee9a
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.
src/basic/time-util.h
src/basic/util.h