diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-01 17:54:59 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-01 17:54:59 -0700 |
commit | c4483576b8d30fadcae208d8f12383febd060d0a (patch) | |
tree | a062ffc614a516f3ee2090f9336e86d0ed8091e6 /sha1_file.c | |
parent | f35ca9ed3ef02541a938f3bd43cad83af93eb94f (diff) | |
download | git-c4483576b8d30fadcae208d8f12383febd060d0a.tar.gz |
Add "unpack_sha1_header()" helper function
It's for people who aren't necessarily interested in the whole
unpacked file, but do want to know the header information (size,
type, etc..)
For example, the delta code can use this to figure out whether
an object is already a delta object, and what it is a delta
against, without actually bothering to unpack all of the actual
data in the delta.
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/sha1_file.c b/sha1_file.c index ac7bf9fd27..bc3d70fdd6 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -307,6 +307,19 @@ void *map_sha1_file(const unsigned char *sha1, unsigned long *size) return map; } +int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size) +{ + /* Get the data stream */ + memset(stream, 0, sizeof(*stream)); + stream->next_in = map; + stream->avail_in = mapsize; + stream->next_out = buffer; + stream->avail_out = size; + + inflateInit(stream); + return inflate(stream, 0); +} + void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size) { int ret, bytes; @@ -314,18 +327,8 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned l char buffer[8192]; unsigned char *buf; - /* Get the data stream */ - memset(&stream, 0, sizeof(stream)); - stream.next_in = map; - stream.avail_in = mapsize; - stream.next_out = (unsigned char *)buffer; - stream.avail_out = sizeof(buffer); - - inflateInit(&stream); - ret = inflate(&stream, 0); - if (ret < Z_OK) - return NULL; - if (sscanf(buffer, "%10s %lu", type, size) != 2) + ret = unpack_sha1_header(&stream, map, mapsize, buffer, sizeof(buffer)); + if (ret < Z_OK || sscanf(buffer, "%10s %lu", type, size) != 2) return NULL; bytes = strlen(buffer) + 1; |