From a2dff61c487ee42184612ae2d4445fadb5ddb5e3 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Wed, 27 Aug 2008 14:57:51 +0100 Subject: [PATCH] stubdom: add v?errx? and v?warnx? functions Signed-off-by: Samuel Thibault --- include/posix/err.h | 15 +++++++++++ lib/sys.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 include/posix/err.h diff --git a/include/posix/err.h b/include/posix/err.h new file mode 100644 index 0000000..1079f58 --- /dev/null +++ b/include/posix/err.h @@ -0,0 +1,15 @@ +#ifndef _POSIX_ERR_H +#define _POSIX_ERR_H + +#include + +void err(int eval, const char *fmt, ...); +void errx(int eval, const char *fmt, ...); +void warn(const char *fmt, ...); +void warnx(const char *fmt, ...); +void verr(int eval, const char *fmt, va_list args); +void verrx(int eval, const char *fmt, va_list args); +void vwarn(const char *fmt, va_list args); +void vwarnx(const char *fmt, va_list args); + +#endif /* _POSIX_ERR_H */ diff --git a/lib/sys.c b/lib/sys.c index 21e3b1f..47bbbda 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -1035,6 +1035,68 @@ void closelog(void) syslog_ident = NULL; } +void vwarn(const char *format, va_list ap) +{ + int the_errno = errno; + printk("stubdom: "); + if (format) { + print(0, format, ap); + printk(", "); + } + printk("%s", strerror(the_errno)); +} + +void warn(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + vwarn(format, ap); + va_end(ap); +} + +void verr(int eval, const char *format, va_list ap) +{ + vwarn(format, ap); + exit(eval); +} + +void err(int eval, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + verr(eval, format, ap); + va_end(ap); +} + +void vwarnx(const char *format, va_list ap) +{ + printk("stubdom: "); + if (format) + print(0, format, ap); +} + +void warnx(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + vwarnx(format, ap); + va_end(ap); +} + +void verrx(int eval, const char *format, va_list ap) +{ + vwarnx(format, ap); + exit(eval); +} + +void errx(int eval, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + verrx(eval, format, ap); + va_end(ap); +} + int nanosleep(const struct timespec *req, struct timespec *rem) { s_time_t start = NOW(); -- 2.39.5