More strerror - dedup - deduplicating backup program
 (HTM) git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 6b4ed5e72fbc812704fa6659a87d7b91d50a6b0b
 (DIR) parent 78ad139e2acc136eef7c94ff566a1150a9fdfb5b
 (HTM) Author: sin <sin@2f30.org>
       Date:   Fri,  3 May 2019 16:43:44 +0100
       
       More strerror
       
       Diffstat:
         M bcompress.c                         |      15 ++++++++-------
         M bencrypt.c                          |      11 ++++++-----
         M bstorage.c                          |      54 ++++++++++++++++---------------
         M snap.c                              |       5 +++--
       
       4 files changed, 45 insertions(+), 40 deletions(-)
       ---
 (DIR) diff --git a/bcompress.c b/bcompress.c
       @@ -3,6 +3,7 @@
        #include <sys/stat.h>
        
        #include <assert.h>
       +#include <errno.h>
        #include <fcntl.h>
        #include <stdint.h>
        #include <stdio.h>
       @@ -104,7 +105,7 @@ bccreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar)
        
                bctx->cctx = calloc(1, sizeof(struct cctx));
                if (bctx->cctx == NULL) {
       -                bseterr("out of memory");
       +                bseterr("calloc: %s", strerror(errno));
                        return -1;
                }
                cctx = bctx->cctx;
       @@ -126,7 +127,7 @@ bcopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar)
        
                bctx->cctx = calloc(1, sizeof(struct cctx));
                if (bctx->cctx == NULL) {
       -                bseterr("out of memory");
       +                bseterr("calloc: %s", strerror(errno));
                        return -1;
                }
                cctx = bctx->cctx;
       @@ -173,7 +174,7 @@ bcput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)
                /* Allocate compressed block */
                cbuf = malloc(CDSIZE + cn);
                if (cbuf == NULL) {
       -                bseterr("out of memory");
       +                bseterr("malloc: %s", strerror(errno));
                        return -1;
                }
        
       @@ -183,7 +184,7 @@ bcput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)
                } else if (cctx->type == CDSNAPPYTYPE) {
                        if (snappy_compress(buf, n, &cbuf[CDSIZE], &cn) != SNAPPY_OK) {
                                free(cbuf);
       -                        bseterr("failed to compress");
       +                        bseterr("snappy_compress: failed");
                                return -1;
                        }
                } else {
       @@ -225,7 +226,7 @@ bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n)
                /* Allocate compressed block */
                cbuf = malloc(size);
                if (cbuf == NULL) {
       -                bseterr("out of memory");
       +                bseterr("malloc: %s", strerror(errno));
                        return -1;
                }
        
       @@ -252,7 +253,7 @@ bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n)
                        if (snappy_uncompressed_length(&cbuf[CDSIZE], cd.size,
                                                       &un) != SNAPPY_OK) {
                                free(cbuf);
       -                        bseterr("failed to determine uncompressed length");
       +                        bseterr("snappy_uncompressed_length: failed");
                                return -1;
                        }
        
       @@ -265,7 +266,7 @@ bcget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n)
                        if (snappy_uncompress(&cbuf[CDSIZE], cd.size, buf,
                                              &un) != SNAPPY_OK) {
                                free(cbuf);
       -                        bseterr("failed to uncompress");
       +                        bseterr("snappy_uncompress: failed");
                                return -1;
                        }
                } else {
 (DIR) diff --git a/bencrypt.c b/bencrypt.c
       @@ -3,6 +3,7 @@
        #include <sys/stat.h>
        
        #include <assert.h>
       +#include <errno.h>
        #include <fcntl.h>
        #include <stdint.h>
        #include <stdio.h>
       @@ -115,14 +116,14 @@ becreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar)
                }
        
                if (sodium_init() < 0) {
       -                bseterr("crypto library failed to initialize");
       +                bseterr("sodium_init: failed");
                        return -1;
                }
        
                /* Allocate and initialize encryption context */
                bctx->ectx = calloc(1, sizeof(struct ectx));
                if (bctx->ectx == NULL) {
       -                bseterr("out of memory");
       +                bseterr("calloc: %s", strerror(errno));
                        return -1;
                }
                ectx = bctx->ectx;
       @@ -147,7 +148,7 @@ beopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar)
                /* Allocate and initialize encryption context */
                bctx->ectx = calloc(1, sizeof(struct ectx));
                if (bctx->ectx == NULL) {
       -                bseterr("out of memory");
       +                bseterr("calloc: %s", strerror(errno));
                        return -1;
                }
                ectx = bctx->ectx;
       @@ -206,7 +207,7 @@ beput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)
                /* Allocate encrypted block */
                ebuf = malloc(EDSIZE + en);
                if (ebuf == NULL) {
       -                bseterr("out of memory");
       +                bseterr("malloc: %s", strerror(errno));
                        return -1;
                }
        
       @@ -263,7 +264,7 @@ beget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n)
                size = EDSIZE + *n + crypto_aead_xchacha20poly1305_ietf_ABYTES;
                ebuf = malloc(size);
                if (ebuf == NULL) {
       -                bseterr("out of memory");
       +                bseterr("malloc: %s", strerror(errno));
                        return -1;
                }
        
 (DIR) diff --git a/bstorage.c b/bstorage.c
       @@ -137,7 +137,7 @@ unpackbhdr(int fd, struct bhdr *bhdr)
                int n;
        
                if (xread(fd, buf, sizeof(buf)) != sizeof(buf)) {
       -                bseterr("failed to read block header");
       +                bseterr("failed to read block header: %s", strerror(errno));
                        return -1;
                }
        
       @@ -164,7 +164,7 @@ packbhdr(int fd, struct bhdr *bhdr)
        
                assert(n == BHDRSIZE);
                if (xwrite(fd, buf, n) != n) {
       -                bseterr("failed to write block header");
       +                bseterr("failed to write block header: %s", strerror(errno));
                        return -1;
                }
                return n;
       @@ -179,7 +179,8 @@ unpackbd(int fd, struct bd *bd)
                int n;
        
                if (xread(fd, buf, sizeof(buf)) != sizeof(buf)) {
       -                bseterr("failed to read block descriptor");
       +                bseterr("failed to read block descriptor: %s",
       +                        strerror(errno));
                        return -1;
                }
        
       @@ -215,7 +216,8 @@ packbd(int fd, struct bd *bd)
        
                assert(n == BDSIZE);
                if (xwrite(fd, buf, n) != n) {
       -                bseterr("failed to write block descriptor");
       +                bseterr("failed to write block descriptor: %s",
       +                        strerror(errno));
                        return -1;
                }
                return n;
       @@ -229,7 +231,7 @@ loadbd(struct sctx *sctx)
        
                bd = calloc(1, sizeof(*bd));
                if (bd == NULL) {
       -                bseterr("out of memory");
       +                bseterr("calloc: %s", strerror(errno));
                        return -1;
                }
        
       @@ -247,7 +249,7 @@ loadbd(struct sctx *sctx)
                /* Move to the next block descriptor */
                if (lseek(sctx->fd, bd->size, SEEK_CUR) < 0) {
                        free(bd);
       -                bseterr("failed to seek on storage descriptor");
       +                bseterr("lseek: %s", strerror(errno));
                        return -1;
                }
        
       @@ -308,20 +310,20 @@ bscreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar)
                int fd;
        
                if (sodium_init() < 0) {
       -                bseterr("crypto library failed to initialize");
       +                bseterr("sodium_init: failed");
                        return -1;
                }
        
                fd = open(path, O_RDWR | O_CREAT | O_EXCL, mode);
                if (fd < 0) {
       -                bseterr("%s", strerror(errno));
       +                bseterr("open: %s", strerror(errno));
                        return -1;
                }
        
                bctx->sctx = calloc(1, sizeof(struct sctx));
                if (bctx->sctx == NULL) {
                        close(fd);
       -                bseterr("out of memory");
       +                bseterr("calloc: %s", strerror(errno));
                        return -1;
                }
        
       @@ -389,20 +391,20 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar)
                }
        
                if (sodium_init() < 0) {
       -                bseterr("crypto library failed to initialize");
       +                bseterr("sodium_init: failed");
                        return -1;
                }
        
                fd = open(path, flags, mode);
                if (fd < 0) {
       -                bseterr("%s", strerror(errno));
       +                bseterr("open: %s", strerror(errno));
                        return -1;
                }
        
                bctx->sctx = calloc(1, sizeof(struct sctx));
                if (bctx->sctx == NULL) {
                        close(fd);
       -                bseterr("out of memory");
       +                bseterr("calloc: %s", strerror(errno));
                        return -1;
                }
        
       @@ -491,7 +493,7 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)
                off_t offs;
        
                if (bhash(buf, n, key.md) < 0) {
       -                bseterr("failed to hash block");
       +                bseterr("bhash: failed");
                        return -1;
                }
        
       @@ -507,7 +509,7 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)
        
                        bdoffs = bd->offset - BDSIZE;
                        if (lseek(sctx->fd, bdoffs, SEEK_SET) < 0) {
       -                        bseterr("failed to seek on storage descriptor");
       +                        bseterr("lseek: %s", strerror(errno));
                                return -1;
                        }
        
       @@ -524,14 +526,14 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)
                /* New blocks are always appended to the storage file */
                offs = lseek(sctx->fd, 0, SEEK_END);
                if (offs < 0) {
       -                bseterr("failed to seek on storage descriptor");
       +                bseterr("lseek: %s", strerror(errno));
                        return -1;
                }
        
                /* Allocate a new block descriptor */
                bd = calloc(1, sizeof(*bd));
                if (bd == NULL) {
       -                bseterr("out of memory");
       +                bseterr("calloc: %s", strerror(errno));
                        return -1;
                }
                bd->type = BDTYPE;
       @@ -551,7 +553,7 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)
                        /* Shouldn't fail but if it does rewind storage file state */
                        ftruncate(sctx->fd, offs);
                        free(bd);
       -                bseterr("failed to write block");
       +                bseterr("failed to write block: %s", strerror(errno));
                        return -1;
                }
        
       @@ -591,11 +593,11 @@ bsget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n)
                }
        
                if (lseek(sctx->fd, bd->offset, SEEK_SET) < 0) {
       -                bseterr("failed to seek on storage descriptor");
       +                bseterr("lseek: %s", strerror(errno));
                        return -1;
                }
                if (xread(sctx->fd, buf, bd->size) != bd->size) {
       -                bseterr("failed to read block");
       +                bseterr("failed to read block: %s", strerror(errno));
                        return -1;
                }
                *n = bd->size;
       @@ -622,7 +624,7 @@ bsrm(struct bctx *bctx, unsigned char *md)
        
                bdoffs = bd->offset - BDSIZE;
                if (lseek(sctx->fd, bdoffs, SEEK_SET) < 0) {
       -                bseterr("failed to seek on storage descriptor");
       +                bseterr("lseek: %s", strerror(errno));
                        return -1;
                }
        
       @@ -702,25 +704,25 @@ bscheck(struct bctx *bctx, unsigned char *md)
                }
        
                if (lseek(sctx->fd, bd->offset, SEEK_SET) < 0) {
       -                bseterr("failed to seek on storage descriptor");
       +                bseterr("lseek: %s", strerror(errno));
                        return -1;
                }
        
                buf = malloc(bd->size);
                if (buf == NULL) {
       -                bseterr("out of memory");
       +                bseterr("malloc: %s", strerror(errno));
                        return -1;
                }
        
                if (xread(sctx->fd, buf, bd->size) != bd->size) {
                        free(buf);
       -                bseterr("failed to read block");
       +                bseterr("failed to read block: %s", strerror(errno));
                        return -1;
                }
        
                if (bhash(buf, bd->size, key.md) < 0) {
                        free(buf);
       -                bseterr("failed to hash block");
       +                bseterr("bhash: failed");
                        return -1;
                }
        
       @@ -743,7 +745,7 @@ bssync(struct bctx *bctx)
                        return 0;
        
                if (lseek(sctx->fd, 0, SEEK_SET) < 0) {
       -                bseterr("failed to seek on storage descriptor");
       +                bseterr("lseek: %s", strerror(errno));
                        return -1;
                }
                bhdr = &sctx->bhdr;
       @@ -779,7 +781,7 @@ bsclose(struct bctx *bctx)
                r = close(sctx->fd);
                free(sctx);
                if (r < 0)
       -                bseterr("failed to close storage descriptor");
       +                bseterr("close: %s", strerror(errno));
                return r;
        }
        
 (DIR) diff --git a/snap.c b/snap.c
       @@ -47,7 +47,7 @@ loadmd(struct sctx *sctx)
                }
                if (xread(sctx->fd, mdnode->md, MDSIZE) != MDSIZE) {
                        free(mdnode);
       -                sseterr("xread: %s", strerror(errno));
       +                sseterr("failed to read message digest: %s", strerror(errno));
                        return -1;
                }
                SLIST_INSERT_HEAD(&sctx->mdhead, mdnode, e);
       @@ -226,7 +226,8 @@ ssync(struct sctx *sctx)
                }
                SLIST_FOREACH(mdnode, &sctx->mdhead, e) {
                        if (xwrite(sctx->fd, mdnode->md, MDSIZE) != MDSIZE) {
       -                        sseterr("xwrite: %s", strerror(errno));
       +                        sseterr("failed to write message digest: %s",
       +                                strerror(errno));
                                return -1;
                        }
                }