[PATCH] Add doc and install-doc targets to the Makefile
[git.git] / csum-file.c
index 9f9553a..907efbf 100644 (file)
@@ -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);
@@ -85,7 +86,7 @@ struct sha1file *sha1create(const char *fmt, ...)
                die("you wascally wabbit, you");
        f->namelen = len;
 
-       fd = open(f->name, O_CREAT | O_EXCL | O_WRONLY, 0644);
+       fd = open(f->name, O_CREAT | O_EXCL | O_WRONLY, 0666);
        if (fd < 0)
                die("unable to open %s (%s)", f->name, strerror(errno));
        f->fd = fd;
@@ -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;