Use an int directly instead of wrapper struct - 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 85c3683e1b6a3a087edc3c55efe746ae888a4773
 (DIR) parent 806f791ed702e6cbc0aad2a374c53f244ab420f2
 (HTM) Author: sin <sin@2f30.org>
       Date:   Mon,  4 Mar 2019 15:29:47 +0000
       
       Use an int directly instead of wrapper struct
       
       Diffstat:
         M dedup.c                             |      37 +++++++++++++++++++------------
       
       1 file changed, 23 insertions(+), 14 deletions(-)
       ---
 (DIR) diff --git a/dedup.c b/dedup.c
       @@ -25,10 +25,6 @@ enum {
                WALK_STOP
        };
        
       -struct check_cache_args {
       -        int ret;
       -};
       -
        struct extract_args {
                uint8_t *md;
                int fd;
       @@ -359,9 +355,16 @@ check_snap(struct snapshot *snap, void *arg)
        {
                uint8_t md[MDSIZE];
                uint8_t *buf;
       +        int *ret = arg;
                SHA256_CTX ctx;
                uint64_t i;
        
       +        if (verbose > 0) {
       +                fprintf(stderr, "Checking snapshot: ");
       +                print_md(stderr, snap->md, sizeof(snap->md));
       +                fputc('\n', stderr);
       +        }
       +
                buf = alloc_buf(compr_size(BLKSIZE_MAX));
                for (i = 0; i < snap->nr_blk_descs; i++) {
                        struct blk_desc *blk_desc;
       @@ -378,7 +381,7 @@ check_snap(struct snapshot *snap, void *arg)
        
                        fprintf(stderr, "Block hash mismatch\n");
                        fprintf(stderr, "  Expected hash: ");
       -                print_md(stderr, snap->md, sizeof(snap->md));
       +                print_md(stderr, blk_desc->md, sizeof(blk_desc->md));
                        fputc('\n', stderr);
                        fprintf(stderr, "  Actual hash: ");
                        print_md(stderr, md, sizeof(md));
       @@ -387,6 +390,7 @@ check_snap(struct snapshot *snap, void *arg)
                                (unsigned long long)blk_desc->offset);
                        fprintf(stderr, "  Size: %llu\n",
                                (unsigned long long)blk_desc->size);
       +                *ret = -1;
                }
                free_buf(buf);
                return WALK_CONTINUE;
       @@ -401,7 +405,7 @@ check_snap(struct snapshot *snap, void *arg)
        static int
        check_cache(struct snapshot *snap, void *arg)
        {
       -        struct check_cache_args *args = arg;
       +        int *ret = arg;
                uint64_t i;
        
                for (i = 0; i < snap->nr_blk_descs; i++) {
       @@ -411,11 +415,10 @@ check_cache(struct snapshot *snap, void *arg)
                        blk_desc = &snap->blk_desc[i];
                        memcpy(&cache_entry.md, blk_desc->md, sizeof(cache_entry.md));
                        if (lookup_cache_entry(cache, &cache_entry) < 0) {
       -                        args->ret = -1;
       +                        *ret = -1;
                                return WALK_STOP;
                        }
                }
       -        args->ret = 0;
                return WALK_CONTINUE;
        }
        
       @@ -740,17 +743,23 @@ main(int argc, char *argv[])
                }
        
                if (cflag) {
       -                struct check_cache_args args;
       +                int ret;
        
                        xlseek(ifd, SNAP_HDR_SIZE, SEEK_SET);
       -                walk_snap(check_snap, NULL);
       +                ret = 0;
       +                walk_snap(check_snap, &ret);
       +                if (ret != 0)
       +                        errx(1, ".snapshots or .store is corrupted");
        
       -                args.ret = -1;
       -                if (cache_nr_entries() == snap_hdr.st.nr_blks) {
       +                if (cache_nr_entries() != snap_hdr.st.nr_blks) {
       +                        ret = -1;
       +                } else {
                                xlseek(ifd, SNAP_HDR_SIZE, SEEK_SET);
       -                        walk_snap(check_cache, &args);
       +                        ret = 0;
       +                        walk_snap(check_cache, &ret);
                        }
       -                if (args.ret != 0) {
       +
       +                if (ret != 0) {
                                free_cache(cache);
                                cache = alloc_cache();