URI: 
       Put xread/xwrite to misc.c - dedup - deduplicating backup program
  HTML git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit 7a2e4a88b5471cb53583ea7df33ec8c79efa5e38
   DIR parent 53b588c7899ecf4f4c969259e2c80f18192893ba
  HTML Author: sin <sin@2f30.org>
       Date:   Sat, 27 Apr 2019 18:42:20 +0100
       
       Put xread/xwrite to misc.c
       
       Diffstat:
         M Makefile                            |       1 +
         M bstorage.c                          |      42 ++-----------------------------
         M chunker.c                           |      22 ++--------------------
         M dup-unpack.c                        |      22 ++--------------------
         A misc.c                              |      43 ++++++++++++++++++++++++++++++
         M snap.c                              |      43 +++----------------------------
       
       6 files changed, 53 insertions(+), 120 deletions(-)
       ---
   DIR diff --git a/Makefile b/Makefile
       @@ -21,6 +21,7 @@ COMMOBJ = \
                block.o \
                bstorage.o \
                chunker.o \
       +        misc.o \
                pack.o \
                snap.o \
                unpack.o \
   DIR diff --git a/bstorage.c b/bstorage.c
       @@ -49,6 +49,8 @@
        #define CSNAPPYTYPE        1
        #define HBLAKE2BTYPE        0
        
       +extern ssize_t xread(int fd, void *buf, size_t nbytes);
       +extern ssize_t xwrite(int fd, void *buf, size_t nbytes);
        extern int pack(unsigned char *dst, char *fmt, ...);
        extern int unpack(unsigned char *src, char *fmt, ...);
        
       @@ -129,46 +131,6 @@ bhash(void *buf, size_t n, unsigned char *md)
                return blake2b_final(&ctx, md, MDSIZE);
        }
        
       -static ssize_t
       -xread(int fd, void *buf, size_t nbytes)
       -{
       -        unsigned char *bp = buf;
       -        ssize_t total = 0;
       -
       -        while (nbytes > 0) {
       -                ssize_t n;
       -
       -                n = read(fd, &bp[total], nbytes);
       -                if (n < 0)
       -                        return -1;
       -                else if (n == 0)
       -                        return total;
       -                total += n;
       -                nbytes -= n;
       -        }
       -        return total;
       -}
       -
       -static ssize_t
       -xwrite(int fd, void *buf, size_t nbytes)
       -{
       -        unsigned char *bp = buf;
       -        ssize_t total = 0;
       -
       -        while (nbytes > 0) {
       -                ssize_t n;
       -
       -                n = write(fd, &bp[total], nbytes);
       -                if (n < 0)
       -                        return -1;
       -                else if (n == 0)
       -                        return total;
       -                total += n;
       -                nbytes -= n;
       -        }
       -        return total;
       -}
       -
        /* Read block header */
        static int
        unpackbhdr(int fd, struct bhdr *bhdr)
   DIR diff --git a/chunker.c b/chunker.c
       @@ -6,6 +6,8 @@
        
        #define ROTL(x, y) (((x) << (y)) | ((x) >> (32 - (y))))
        
       +extern ssize_t xread(int fd, void *buf, size_t nbytes);
       +
        struct chunker {
                unsigned char *buf;
                int fd;
       @@ -61,26 +63,6 @@ static const uint32_t buztbl[] = {
                0x8dfd4d53,0xc4d0c087,0x31dfb5ca,0xa44589b5,0x6b637e2e,0x663f6b45,0xd2d8baa0,0x1dac7e4c
        };
        
       -static ssize_t
       -xread(int fd, void *buf, size_t nbytes)
       -{
       -        unsigned char *bp = buf;
       -        ssize_t total = 0;
       -
       -        while (nbytes > 0) {
       -                ssize_t n;
       -
       -                n = read(fd, &bp[total], nbytes);
       -                if (n < 0)
       -                        return -1;
       -                else if (n == 0)
       -                        return total;
       -                total += n;
       -                nbytes -= n;
       -        }
       -        return total;
       -}
       -
        /* Buzhash: https://en.wikipedia.org/wiki/Rolling_hash#Cyclic_polynomial */
        static inline uint32_t
        hinit(unsigned char *buf, size_t size)
   DIR diff --git a/dup-unpack.c b/dup-unpack.c
       @@ -12,29 +12,11 @@
        #include "config.h"
        #include "snap.h"
        
       +extern ssize_t xwrite(int fd, void *buf, size_t nbytes);
       +
        int verbose;
        char *argv0;
        
       -static ssize_t
       -xwrite(int fd, void *buf, size_t nbytes)
       -{
       -        unsigned char *bp = buf;
       -        ssize_t total = 0;
       -
       -        while (nbytes > 0) {
       -                ssize_t n;
       -
       -                n = write(fd, &bp[total], nbytes);
       -                if (n < 0)
       -                        return -1;
       -                else if (n == 0)
       -                        return total;
       -                total += n;
       -                nbytes -= n;
       -        }
       -        return total;
       -}
       -
        static int
        unpack(struct sctx *sctx, struct bctx *bctx)
        {
   DIR diff --git a/misc.c b/misc.c
       @@ -0,0 +1,43 @@
       +#include <sys/types.h>
       +
       +#include <unistd.h>
       +
       +ssize_t
       +xread(int fd, void *buf, size_t nbytes)
       +{
       +        unsigned char *bp = buf;
       +        ssize_t total = 0;
       +
       +        while (nbytes > 0) {
       +                ssize_t n;
       +
       +                n = read(fd, &bp[total], nbytes);
       +                if (n < 0)
       +                        return -1;
       +                else if (n == 0)
       +                        return total;
       +                total += n;
       +                nbytes -= n;
       +        }
       +        return total;
       +}
       +
       +ssize_t
       +xwrite(int fd, void *buf, size_t nbytes)
       +{
       +        unsigned char *bp = buf;
       +        ssize_t total = 0;
       +
       +        while (nbytes > 0) {
       +                ssize_t n;
       +
       +                n = write(fd, &bp[total], nbytes);
       +                if (n < 0)
       +                        return -1;
       +                else if (n == 0)
       +                        return total;
       +                total += n;
       +                nbytes -= n;
       +        }
       +        return total;
       +}
   DIR diff --git a/snap.c b/snap.c
       @@ -14,6 +14,9 @@
        #include "queue.h"
        #include "snap.h"
        
       +extern ssize_t xread(int fd, void *buf, size_t nbytes);
       +extern ssize_t xwrite(int fd, void *buf, size_t nbytes);
       +
        struct mdnode {
                unsigned char md[MDSIZE];
                SLIST_ENTRY(mdnode) e;
       @@ -26,46 +29,6 @@ struct sctx {
                int rdonly;
        };
        
       -static ssize_t
       -xread(int fd, void *buf, size_t nbytes)
       -{
       -        uint8_t *bp = buf;
       -        ssize_t total = 0;
       -
       -        while (nbytes > 0) {
       -                ssize_t n;
       -
       -                n = read(fd, &bp[total], nbytes);
       -                if (n < 0)
       -                        return -1;
       -                else if (n == 0)
       -                        return total;
       -                total += n;
       -                nbytes -= n;
       -        }
       -        return total;
       -}
       -
       -static ssize_t
       -xwrite(int fd, void *buf, size_t nbytes)
       -{
       -        uint8_t *bp = buf;
       -        ssize_t total = 0;
       -
       -        while (nbytes > 0) {
       -                ssize_t n;
       -
       -                n = write(fd, &bp[total], nbytes);
       -                if (n < 0)
       -                        return -1;
       -                else if (n == 0)
       -                        return total;
       -                total += n;
       -                nbytes -= n;
       -        }
       -        return total;
       -}
       -
        static int
        loadmd(struct sctx *sctx)
        {