dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit 5e2a473da8667cab7b0df876ffa9e02ff2dae096
parent 444786bf6ec93a0d2cdce9bcb5b87dd67a18281f
Author: sin <sin@2f30.org>
Date:   Fri,  3 May 2019 14:51:23 +0100

Add error reporting functions for snapshots

Diffstat:
Msnap.c | 26++++++++++++++++++++++++++
Msnap.h | 2++
2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/snap.c b/snap.c @@ -4,6 +4,7 @@ #include <fcntl.h> #include <limits.h> +#include <stdarg.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -14,6 +15,7 @@ #include "queue.h" #include "snap.h" +#define NERRBUF 128 extern ssize_t xread(int, void *, size_t); extern ssize_t xwrite(int, void *, size_t); @@ -29,6 +31,8 @@ struct sctx { int rdonly; }; +static char errbuf[NERRBUF]; + static int loadmd(struct sctx *sctx) { @@ -221,3 +225,25 @@ sclose(struct sctx *sctx) free(sctx); return r; } + +void +sseterr(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsnprintf(errbuf, NERRBUF, fmt, ap); + va_end(ap); +} + +void +serr(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": %s\n", errbuf); + va_end(ap); + exit(1); +} diff --git a/snap.h b/snap.h @@ -11,3 +11,5 @@ extern int sget(struct sctx *, unsigned char *); extern int srewind(struct sctx *); extern int ssync(struct sctx *); extern int sclose(struct sctx *); +extern void sseterr(char *, ...); +extern void serr(char *, ...);