diff --git a/Makefile b/Makefile index 1cb031a..f070b08 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,10 @@ install : $(PROGRAMS) cp $^ $(HOME)/bin/ dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o \ - proc-cache.o dlhist.o error.o -dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o error.o -dlight-read-config : read-config.o buffer.o env.o cconf.o error.o + sha1_io.o proc-cache.o dlhist.o error.o +dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o \ + sha1_io.o error.o +dlight-read-config : read-config.o buffer.o env.o cconf.o sha1_io.o error.o dlight-filter-check: filter-check.o filter.o error.o dlight-% : %.o diff --git a/cconf.c b/cconf.c index 282c9b8..d16a9e4 100644 --- a/cconf.c +++ b/cconf.c @@ -25,25 +25,13 @@ #include #include #include -#include #include +#include "sha1_io.h" #include "cconf.h" /* we count NULL as part of the string ondisk */ #define strsize(str) (strlen(str) + 1) -static int sha1_write(SHA_CTX *ctx, int fd, void *buf, size_t size) { - - SHA1_Update(ctx, buf, size); - return write(fd, buf, size); -} - -static void write_int(SHA_CTX *ctx, int fd, int val) { - - val = htonl(val); - sha1_write(ctx, fd, &val, sizeof val); -} - static void* read_entry_nr(void *buf, unsigned int *out) { memcpy(out, buf, sizeof(*out)); @@ -217,7 +205,7 @@ int cconf_write(int fd, struct cconf *c) { lseek(fd, sizeof(hdr), SEEK_SET); /* put number of targets */ - write_int(&ctx, fd, c->nr); + sha1_write_int(&ctx, fd, c->nr); for(i = 0; i < c->nr; i++) { int j; @@ -229,7 +217,7 @@ int cconf_write(int fd, struct cconf *c) { sha1_write(&ctx, fd, target->src, strsize(target->src)); /* write number of filters */ - write_int(&ctx, fd, target->nr); + sha1_write_int(&ctx, fd, target->nr); for(j=0; j < target->nr; j++) { struct filter *f = &target->filter[j];