aboutsummaryrefslogtreecommitdiff
path: root/src/binlogcat.c
diff options
context:
space:
mode:
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
@@ -20,6 +20,7 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <errno.h>
#include <time.h>
#include <string.h>
@@ -33,6 +34,34 @@ int verbose_option;
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)
{
FILE *fp;
@@ -52,40 +81,37 @@ catlog(const char *fname)
else {
fp = fopen(fname, "r");
if (!fp) {
- fprintf(stderr, "%s: cannot open %s: %s\n",
- progname, fname, strerror(errno));
+ error("cannot open %s: %s", strerror(errno));
exit(1);
}
}
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);
}
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);
}
if (header.version != BINLOG_VERSION) {
- fprintf(stderr, "%s: %s: unknown version\n",
- progname, fname);
+ error("%s: unknown version", progname, fname);
exit(1);
}
size = header.hdrsize - sizeof(header);
dataspec = malloc(size);
if (!dataspec) {
- fprintf(stderr, "%s: not enough memory", progname);
+ error("not enough memory");
abort();
}
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);
}
@@ -95,15 +121,14 @@ catlog(const char *fname)
inst = packcomp(dataspec, &p);
if (*p) {
- fprintf(stderr, "%s: %s: bad dataspec near %s",
- progname, dataspec, p);
+ error("%s: bad dataspec near %s", dataspec, p);
exit(1);
}
free(dataspec);
rec = malloc(header.recsize);
if (!rec) {
- fprintf(stderr, "%s: not enough memory", progname);
+ error("not enough memory");
abort();
}
env = packenv_create(header.recsize -
@@ -112,8 +137,7 @@ catlog(const char *fname)
for (i = 0; i < header.recnum; i++) {
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.