blob: 05500beadc957bfaaec809da506c010bccf000be [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#ifndef AOS_COMMON_DIE_H_
2#define AOS_COMMON_DIE_H_
3
4#include <stdarg.h>
5
Brian Silvermanf7986142014-04-21 17:42:35 -07006#include "aos/common/macros.h"
Brian Silverman01be0002014-05-10 15:44:38 -07007#include "aos/common/util/aos_strerror.h"
Brian Silvermanf7986142014-04-21 17:42:35 -07008
brians343bc112013-02-10 01:53:46 +00009namespace aos {
10
11// Terminates the task/process and logs a message (without using the logging
12// framework). Designed for use in code that can't use the logging framework
13// (code that can should LOG(FATAL), which calls this).
14void Die(const char *format, ...)
15 __attribute__((noreturn))
Brian Silvermanf7986142014-04-21 17:42:35 -070016 __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 1, 2)));
brians343bc112013-02-10 01:53:46 +000017void VDie(const char *format, va_list args)
18 __attribute__((noreturn))
Brian Silvermanf7986142014-04-21 17:42:35 -070019 __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 1, 0)));
brians343bc112013-02-10 01:53:46 +000020
Brian Silverman01be0002014-05-10 15:44:38 -070021
22// The same as Die except appends " because of %d (%s)" (formatted with errno
23// and aos_strerror(errno)) to the message.
24#define PDie(format, args...) \
25 do { \
26 const int error = errno; \
27 ::aos::Die(format " because of %d (%s)", ##args, error, \
28 aos_strerror(error)); \
29 } while (false);
30
Brian Silverman8d2e56e2013-09-23 17:55:03 -070031// Turns on (or off) "test mode", where (V)Die doesn't write out files and
32// doesn't print to stdout.
33// Test mode defaults to false.
34void SetDieTestMode(bool test_mode);
35
brians343bc112013-02-10 01:53:46 +000036} // namespace aos
37
38#endif // AOS_COMMON_DIE_H_