summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f35ca9e)
raw | patch | inline | side by side (parent: f35ca9e)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Thu, 2 Jun 2005 00:54:59 +0000 (17:54 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Thu, 2 Jun 2005 00:54:59 +0000 (17:54 -0700) |
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.
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.
cache.h | patch | blob | history | |
sha1_file.c | patch | blob | history |
index d38d9a848c2fa0793bb849f17e33e75efc927bc7..69b63ba1d40d7891b9814fa97535fc6489564ad8 100644 (file)
--- a/cache.h
+++ b/cache.h
/* 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 ac7bf9fd271cd538e733d31332ab29cf36e4a69f..bc3d70fdd63bba3e508a23bc983590e5bbd3f8f5 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
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;