From: John Kacur <jkacur@redhat.com>
To: Clark Williams <williams@redhat.com>,
Carsten Emde <carsten.emde@osadl.org>
Cc: John Kacur <jkacur@redhat.com>,
rt-users <linux-rt-users@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 1/5] rt-tests: Add error routines to the library
Date: Wed, 23 Dec 2009 17:02:56 +0100 [thread overview]
Message-ID: <1261584180-13922-2-git-send-email-jkacur@redhat.com> (raw)
In-Reply-To: <1261584180-13922-1-git-send-email-jkacur@redhat.com>
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@redhat.com>
---
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
next prev parent reply other threads:[~2009-12-23 16:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-23 16:02 [PATCH 0/5] *** Add new priority inversion test, plus lib changes *** John Kacur
2009-12-23 16:02 ` John Kacur [this message]
2009-12-23 16:02 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes John Kacur
2009-12-23 16:02 ` [PATCH 3/5] rt-tests: Move header files from src/lib to src/include John Kacur
2009-12-23 16:02 ` [PATCH 4/5] rt-tests: pip - Use check_privs() from the rt-utils library John Kacur
2009-12-23 16:03 ` [PATCH 5/5] rt-tests: Add a "make tags" option John Kacur
2009-12-23 22:52 ` [PATCH 2/5] rt-tests: Add a new test pip - priority inheritance with processes Carsten Emde
2009-12-23 23:25 ` John Kacur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1261584180-13922-2-git-send-email-jkacur@redhat.com \
--to=jkacur@redhat.com \
--cc=carsten.emde@osadl.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).