diff options
Diffstat (limited to 'sys/libn/error.c')
-rw-r--r-- | sys/libn/error.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/sys/libn/error.c b/sys/libn/error.c index 15611a3..9b6a28a 100644 --- a/sys/libn/error.c +++ b/sys/libn/error.c @@ -2,7 +2,7 @@ #include <libn.h> void -errorf(const byte* fmt, ...) +errorf(byte* fmt, ...) { va_list args; va_start(args, fmt); @@ -13,3 +13,57 @@ errorf(const byte* fmt, ...) va_end(args); } + +void +panicf(byte* fmt, ...) +{ + int n; + va_list args; + static byte buf[4*1024]; + va_start(args, fmt); + + buf[0] = 'p'; + buf[1] = 'a'; + buf[2] = 'n'; + buf[3] = 'i'; + buf[4] = 'c'; + buf[5] = ':'; + buf[6] = ' '; + n = vsnprintf(buf+7, arrlen(buf)-8, fmt, args); + if (n < 0) + return; + buf[n] = 0; + + perror(buf); + va_end(args); + + /* TODO: portable stack unwinding */ + exit(1); +} + +void +vpanicf(byte* fmt, va_list args) +{ + int n; + va_list nargs; + static byte buf[4*1024]; + va_copy(nargs, args); + + buf[0] = 'p'; + buf[1] = 'a'; + buf[2] = 'n'; + buf[3] = 'i'; + buf[4] = 'c'; + buf[5] = ':'; + buf[6] = ' '; + n = vsnprintf(buf+7, arrlen(buf)-8, fmt, args); + if (n < 0) + return; + buf[n] = 0; + + perror(buf); + va_end(nargs); + + /* TODO: portable stack unwinding */ + exit(1); +} |