[PATCH 1/5] rt-tests: Add error routines to the library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add error routines, similar to those found in Advanced Programming in the
UNIX Environment 2nd ed. for use by all rt test programs

Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>
---
 src/lib/error.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/lib/error.h |   14 ++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)
 create mode 100644 src/lib/error.c
 create mode 100644 src/lib/error.h

diff --git a/src/lib/error.c b/src/lib/error.c
new file mode 100644
index 0000000..d5ad2aa
--- /dev/null
+++ b/src/lib/error.c
@@ -0,0 +1,49 @@
+#include "error.h"
+
+/* Print an error message, plus a message for err and exit with error err */
+void err_exit(int err, char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	err_doit(err, fmt, ap);
+	va_end(ap);
+	exit(err);
+}
+
+/* print an error message and return */
+void err_msg(char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	err_doit(0, fmt, ap);
+	va_end(ap);
+	return;
+}
+
+/* Print an error message, plus a message for err, and return */
+void err_msg_n(int err, char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	err_doit(err, fmt, ap);
+	va_end(ap);
+	return;
+}
+
+/* print an error message and quit */
+void err_quit(char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	err_doit(0, fmt, ap);
+	va_end(ap);
+	exit(1);
+}
+
+void err_doit(int err, const char *fmt, va_list ap)
+{
+	if (err)
+		fprintf(stderr, "%s\n", strerror(err));
+	vfprintf(stderr, fmt, ap);
+	return;
+}
diff --git a/src/lib/error.h b/src/lib/error.h
new file mode 100644
index 0000000..90d6e94
--- /dev/null
+++ b/src/lib/error.h
@@ -0,0 +1,14 @@
+#ifndef __ERROR_H
+#define __ERROR_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+void err_exit(int err, char *fmt, ...);
+void err_msg(char *fmt, ...);
+void err_msg_n(int err, char *fmt, ...);
+void err_quit(char *fmt, ...);
+void err_doit(int err, const char *fmt, va_list ap);
+
+#endif	/* __ERROR_H */
-- 
1.6.5.2

--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux