X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=csum-file.c;h=c8c7369152cd2b744aae488eb794c12ffbdfe9b9;hb=a61eea6abdbd336c7a3364c170cce3de01421599;hp=9f9553ae035e762d12dc7d885432abd920af6e5b;hpb=e18088451d92fbf83bfb57fd48201eda117f8103;p=git.git diff --git a/csum-file.c b/csum-file.c index 9f9553ae..c8c73691 100644 --- a/csum-file.c +++ b/csum-file.c @@ -58,6 +58,7 @@ int sha1write(struct sha1file *f, void *buf, unsigned int count) memcpy(f->buffer + offset, buf, nr); count -= nr; offset += nr; + buf += nr; left -= nr; if (!left) { SHA1_Update(&f->ctx, f->buffer, offset); @@ -95,6 +96,26 @@ struct sha1file *sha1create(const char *fmt, ...) return f; } +struct sha1file *sha1fd(int fd, const char *name) +{ + struct sha1file *f; + unsigned len; + + f = xmalloc(sizeof(*f)); + + len = strlen(name); + if (len >= PATH_MAX) + die("you wascally wabbit, you"); + f->namelen = len; + memcpy(f->name, name, len+1); + + f->fd = fd; + f->error = 0; + f->offset = 0; + SHA1_Init(&f->ctx); + return f; +} + int sha1write_compressed(struct sha1file *f, void *in, unsigned int size) { z_stream stream;