commit ba614e8d68f1c26d9c6bcd9ad0f67523359379ea
parent 48f31f0e4374a1a6a8e4c1781390d64f256d355f
Author: sin <sin@2f30.org>
Date: Mon, 13 May 2019 23:23:27 +0100
chunker: Call seterr()
Also make cdrain() and cclose() void as they cannot fail.
Diffstat:
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/chunker.c b/chunker.c
@@ -129,12 +129,15 @@ copen(int fd, size_t minsize, size_t maxsize,
struct chunker *c;
c = calloc(1, sizeof(*c));
- if (c == NULL)
+ if (c == NULL) {
+ seterr("calloc: out of memory");
return NULL;
+ }
c->buf = calloc(1, maxsize);
if (c->buf == NULL) {
free(c);
+ seterr("calloc: out of memory");
return NULL;
}
@@ -146,7 +149,7 @@ copen(int fd, size_t minsize, size_t maxsize,
return c;
}
-int
+void
cclose(struct chunker *c)
{
free(c->buf);
@@ -173,6 +176,7 @@ cget(struct chunker *c, size_t *csize)
if (c->rp == c->wp) {
*csize = 0;
+ seterr("chunker underflow");
return NULL;
}
@@ -182,7 +186,7 @@ cget(struct chunker *c, size_t *csize)
return bp;
}
-int
+void
cdrain(struct chunker *c)
{
unsigned char *src, *dst;
diff --git a/chunker.h b/chunker.h
@@ -1,7 +1,7 @@
struct chunker;
extern struct chunker *copen(int, size_t, size_t, size_t, size_t);
-extern int cclose(struct chunker *);
+extern void cclose(struct chunker *);
extern ssize_t cfill(struct chunker *);
extern void *cget(struct chunker *, size_t *);
-extern int cdrain(struct chunker *);
+extern void cdrain(struct chunker *);
diff --git a/dup-pack.c b/dup-pack.c
@@ -63,7 +63,7 @@ pack(struct sctx *sctx, struct bctx *bctx)
struct chunker *c;
if ((c = copen(0, BSIZEMIN, BSIZEMAX, HMASKBITS, WINSIZE)) == NULL)
- errx(1, "copen: failed");
+ printerr("copen");
while (cfill(c) > 0) {
unsigned char md[MDSIZE];
@@ -72,16 +72,14 @@ pack(struct sctx *sctx, struct bctx *bctx)
buf = cget(c, &n);
if (buf == NULL)
- errx(1, "cget: failed");
+ printerr("cget");
if (bput(bctx, buf, n, md) < 0)
printerr("bput");
if (sput(sctx, md) < 0)
printerr("sput");
- if (cdrain(c) < 0)
- errx(1, "cdrain: failed");
+ cdrain(c);
}
- if (cclose(c) < 0)
- errx(1, "cclose: failed");
+ cclose(c);
}
static void