aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cache.h1
-rw-r--r--sha1_file.c27
2 files changed, 16 insertions, 12 deletions
diff --git a/cache.h b/cache.h
index d38d9a848..69b63ba1d 100644
--- a/cache.h
+++ b/cache.h
@@ -151,6 +151,7 @@ extern char *sha1_file_name(const unsigned char *sha1);
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
extern void * map_sha1_file(const unsigned char *sha1, unsigned long *size);
+extern int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size);
extern void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size);
extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
diff --git a/sha1_file.c b/sha1_file.c
index ac7bf9fd2..bc3d70fdd 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;