diff options
author | Clark Williams <williams@redhat.com> | 2010-01-13 10:42:35 -0600 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2010-01-13 10:42:35 -0600 |
commit | 99d07bebf340286c0e0b8affa60ead5354ecf289 (patch) | |
tree | 75ab64c35de1c7a25a8d298b948ceee46a88787b | |
parent | 015025fb4db2db8c20a01afcd1b2f74324e306a8 (diff) | |
download | rt-tests-99d07bebf340286c0e0b8affa60ead5354ecf289.tar.gz |
added warn() and fatal() routines
Added routines to print warning and fatal messages with appropriate
text prefixes (e.g. WARNING: and FATAL: )
Signed-off-by: Clark Williams <williams@redhat.com>
-rw-r--r-- | src/include/rt-utils.h | 4 | ||||
-rw-r--r-- | src/lib/rt-utils.c | 24 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h index cc23c33..68857f3 100644 --- a/src/include/rt-utils.h +++ b/src/include/rt-utils.h @@ -1,6 +1,7 @@ #ifndef __RT_UTILS_H #define __RT_UTILS_H + #define _STR(x) #x #define STR(x) _STR(x) #define MAX_PATH 256 @@ -8,4 +9,7 @@ int check_privs(void); char *get_debugfileprefix(void); +void warn(char *fmt, ...); +void fatal(char *fmt, ...); + #endif /* __RT_UTILS.H */ diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c index 417c38b..c760f5a 100644 --- a/src/lib/rt-utils.c +++ b/src/lib/rt-utils.c @@ -1,6 +1,8 @@ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sched.h> +#include <stdarg.h> #include "rt-utils.h" static char debugfileprefix[MAX_PATH]; @@ -64,3 +66,25 @@ int check_privs(void) sched_setscheduler(0, policy, NULL); return 0; } + +void warn(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fputs("WARNING: ", stderr); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + +void fatal(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fputs("FATAL: ", stderr); + vfprintf(stderr, fmt, ap); + va_end(ap); + exit(EXIT_FAILURE); +} + |