brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #ifndef AOS_COMMON_DIE_H_ |
| 2 | #define AOS_COMMON_DIE_H_ |
| 3 | |
| 4 | #include <stdarg.h> |
| 5 | |
Brian Silverman | f798614 | 2014-04-21 17:42:35 -0700 | [diff] [blame] | 6 | #include "aos/common/macros.h" |
Brian Silverman | af78486 | 2014-05-13 08:14:55 -0700 | [diff] [blame^] | 7 | #include "aos/common/libc/aos_strerror.h" |
Brian Silverman | f798614 | 2014-04-21 17:42:35 -0700 | [diff] [blame] | 8 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 9 | namespace 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). |
| 14 | void Die(const char *format, ...) |
| 15 | __attribute__((noreturn)) |
Brian Silverman | f798614 | 2014-04-21 17:42:35 -0700 | [diff] [blame] | 16 | __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 1, 2))); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 17 | void VDie(const char *format, va_list args) |
| 18 | __attribute__((noreturn)) |
Brian Silverman | f798614 | 2014-04-21 17:42:35 -0700 | [diff] [blame] | 19 | __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 1, 0))); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 20 | |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 21 | |
| 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 Silverman | 8d2e56e | 2013-09-23 17:55:03 -0700 | [diff] [blame] | 31 | // 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. |
| 34 | void SetDieTestMode(bool test_mode); |
| 35 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 36 | } // namespace aos |
| 37 | |
| 38 | #endif // AOS_COMMON_DIE_H_ |