diff options
Diffstat (limited to 'src/binlogcat.c')
-rw-r--r-- | src/binlogcat.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/binlogcat.c b/src/binlogcat.c index 505bbc2..656d8f2 100644 --- a/src/binlogcat.c +++ b/src/binlogcat.c @@ -24,12 +24,13 @@ #include <errno.h> #include <time.h> #include <string.h> #include "vmod-binlog.h" #include "pack.h" #include "err.h" +#include "xalloc.h" char *timefmt = "%c"; int number_option; int verbose_option; int timediff_option; @@ -72,17 +73,13 @@ catlog(const char *fname) if (header.version != BINLOG_VERSION) { error("%s: unknown version", fname); exit(1); } size = header.hdrsize - sizeof(header); - dataspec = malloc(size); - if (!dataspec) { - error("not enough memory"); - abort(); - } + dataspec = xmalloc(size); if (fread(dataspec, size, 1, fp) != 1) { error("error reading header of %s: %s", fname, strerror(errno)); exit(1); } @@ -91,26 +88,22 @@ catlog(const char *fname) printf("# %s; format=%s; recsize=%lu; recnum=%lu\n", fname, dataspec, header.recsize, header.recnum); inst = packcomp(dataspec, &p); if (!inst) { if (errno == EINVAL) { - error("%s: bad dataspec near %s", dataspec, p); + error("%s: %s: bad dataspec near %s", fname, dataspec, p); exit(1); } error("%s", strerror(errno)); exit(1); } free(dataspec); - rec = malloc(header.recsize); - if (!rec) { - error("not enough memory"); - exit(1); - } + rec = xmalloc(header.recsize); env = packenv_create(header.recsize - offsetof(struct binlog_record,data)); env->fp = stdout; for (i = 0; i < header.recnum; i++) { if (fread(rec, header.recsize, 1, fp) != 1) { @@ -144,13 +137,13 @@ catlog(const char *fname) fclose(fp); } void help() { - printf("usage: %s [-dhnv] [t FORMAT] [FILE...]\n", progname); + printf("usage: %s [-dhnv] [-t FORMAT] [FILE...]\n", progname); } int main(int argc, char **argv) { int c; |