-static int write_cache(int newfd, struct cache_entry **cache, int entries)
-{
- SHA_CTX c;
- struct cache_header hdr;
- int i;
-
- hdr.signature = CACHE_SIGNATURE;
- hdr.version = 1;
- hdr.entries = entries;
-
- SHA1_Init(&c);
- SHA1_Update(&c, &hdr, offsetof(struct cache_header, sha1));
- for (i = 0; i < entries; i++) {
- struct cache_entry *ce = cache[i];
- int size = ce_size(ce);
- SHA1_Update(&c, ce, size);
- }
- SHA1_Final(hdr.sha1, &c);
-
- if (write(newfd, &hdr, sizeof(hdr)) != sizeof(hdr))
- return -1;
-
- for (i = 0; i < entries; i++) {
- struct cache_entry *ce = cache[i];
- int size = ce_size(ce);
- if (write(newfd, ce, size) != size)
- return -1;
- }
- return 0;
-}
-