aboutsummaryrefslogtreecommitdiff
path: root/src/binlogcat.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-13 12:13:46 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-10-13 12:13:46 +0300
commit510fc646f13b843d046323e3477edb6c1bc2258d (patch)
tree3de9ea346897300e00ef169fcc84ab508b3d70a3 /src/binlogcat.c
parentfcc1c011757f71bb3ec1c883a19c1945fd83cf11 (diff)
downloadvmod-binlog-510fc646f13b843d046323e3477edb6c1bc2258d.tar.gz
vmod-binlog-510fc646f13b843d046323e3477edb6c1bc2258d.tar.bz2
Improve error reporting.
* src/pack.c: Use packerror to report errors. * src/pack.h (packerror): New proto. * src/binlog.c (packerror): New function. * src/binlogcat.c (packerror,error,verror): New functions.
Diffstat (limited to 'src/binlogcat.c')
-rw-r--r--src/binlogcat.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/src/binlogcat.c b/src/binlogcat.c
index dd36337..8cdfaaa 100644
--- a/src/binlogcat.c
+++ b/src/binlogcat.c
@@ -22,2 +22,3 @@
#include <stdlib.h>
+#include <stdarg.h>
#include <errno.h>
@@ -35,2 +36,30 @@ int timediff_option;
void
+verror(const char *fmt, va_list ap)
+{
+ fprintf(stderr, "%s: ", progname);
+ vfprintf(stderr, fmt, ap);
+ fputc('\n', stderr);
+}
+
+void
+error(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ verror(fmt, ap);
+ va_end(ap);
+}
+
+void
+packerror(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ verror(fmt, ap);
+ va_end(ap);
+}
+
+void
catlog(const char *fname)
@@ -54,4 +83,3 @@ catlog(const char *fname)
if (!fp) {
- fprintf(stderr, "%s: cannot open %s: %s\n",
- progname, fname, strerror(errno));
+ error("cannot open %s: %s", strerror(errno));
exit(1);
@@ -61,4 +89,4 @@ catlog(const char *fname)
if (fread(&header, sizeof(header), 1, fp) != 1) {
- fprintf(stderr, "%s: error reading header of %s: %s\n",
- progname, fname, strerror(errno));
+ error("error reading header of %s: %s",
+ fname, strerror(errno));
exit(1);
@@ -67,4 +95,3 @@ catlog(const char *fname)
if (memcmp(header.magic, BINLOG_MAGIC_STR, BINLOG_MAGIC_LEN)) {
- fprintf(stderr, "%s: %s is not a binlog file\n",
- progname, fname);
+ error("%s is not a binlog file", fname);
exit(1);
@@ -73,4 +100,3 @@ catlog(const char *fname)
if (header.version != BINLOG_VERSION) {
- fprintf(stderr, "%s: %s: unknown version\n",
- progname, fname);
+ error("%s: unknown version", progname, fname);
exit(1);
@@ -81,3 +107,3 @@ catlog(const char *fname)
if (!dataspec) {
- fprintf(stderr, "%s: not enough memory", progname);
+ error("not enough memory");
abort();
@@ -86,4 +112,4 @@ catlog(const char *fname)
if (fread(dataspec, size, 1, fp) != 1) {
- fprintf(stderr, "%s: error reading header of %s: %s\n",
- progname, fname, strerror(errno));
+ error("error reading header of %s: %s",
+ fname, strerror(errno));
exit(1);
@@ -97,4 +123,3 @@ catlog(const char *fname)
if (*p) {
- fprintf(stderr, "%s: %s: bad dataspec near %s",
- progname, dataspec, p);
+ error("%s: bad dataspec near %s", dataspec, p);
exit(1);
@@ -105,3 +130,3 @@ catlog(const char *fname)
if (!rec) {
- fprintf(stderr, "%s: not enough memory", progname);
+ error("not enough memory");
abort();
@@ -114,4 +139,3 @@ catlog(const char *fname)
if (fread(rec, header.recsize, 1, fp) != 1) {
- fprintf(stderr, "%s: %s: unexpected eof\n",
- progname, fname);
+ error("%s: unexpected eof", fname);
break;

Return to:

Send suggestions and report system problems to the System administrator.