Added headerGzRead() and headerGzWrite()
authormarc <devnull@localhost>
Mon, 25 May 1998 03:18:54 +0000 (03:18 +0000)
committermarc <devnull@localhost>
Mon, 25 May 1998 03:18:54 +0000 (03:18 +0000)
CVS patchset: 2127
CVS date: 1998/05/25 03:18:54

CHANGES
lib/header.c
lib/header.h

diff --git a/CHANGES b/CHANGES
index b632f36..1ba6bc8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,7 @@
        - fixed (hopefully) temp file creation problems
        - make %doc obey --test
        - unlink before writing .rpms
+       - librpm.z: added headerGzRead()/headerGzWrite()
 
 2.4.109 -> 2.5:
        - fixed return code bug in build code
index 897de4f..73828c0 100644 (file)
@@ -10,6 +10,8 @@
 #include "config.h"
 #include "miscfn.h"
 
+#include <zlib.h>
+
 #if HAVE_ALLOCA_H
 # include <alloca.h>
 #endif
@@ -329,6 +331,76 @@ Header headerRead(int fd, int magicp)
     return h;
 }
 
+void headerGzWrite(gzFile fd, Header h, int magicp)
+{
+    void * p;
+    int length;
+    int_32 l;
+
+    p = doHeaderUnload(h, &length);
+
+    if (magicp) {
+       gzwrite(fd, header_magic, sizeof(header_magic));
+       l = htonl(0);
+       gzwrite(fd, &l, sizeof(l));
+    }
+    
+    gzwrite(fd, p, length);
+
+    free(p);
+}
+
+Header headerGzRead(gzFile fd, int magicp)
+{
+    int_32 reserved;
+    int_32 * p;
+    int_32 il, dl;
+    int_32 magic;
+    Header h;
+    void * block;
+    int totalSize;
+
+    if (magicp == HEADER_MAGIC_YES) {
+       if (gzread(fd, &magic, sizeof(magic)) != sizeof(magic))
+           return NULL;
+       if (memcmp(&magic, header_magic, sizeof(magic))) {
+           return NULL;
+       }
+
+       if (gzread(fd, &reserved, sizeof(reserved)) != sizeof(reserved))
+           return NULL;
+    }
+    
+    /* First read the index length (count of index entries) */
+    if (gzread(fd, &il, sizeof(il)) != sizeof(il)) 
+       return NULL;
+
+    il = ntohl(il);
+
+    /* Then read the data length (number of bytes) */
+    if (gzread(fd, &dl, sizeof(dl)) != sizeof(dl)) 
+       return NULL;
+
+    dl = ntohl(dl);
+
+    totalSize = sizeof(int_32) + sizeof(int_32) + 
+               (il * sizeof(struct entryInfo)) + dl;
+
+    block = p = malloc(totalSize);
+    *p++ = htonl(il);
+    *p++ = htonl(dl);
+
+    totalSize -= sizeof(int_32) + sizeof(int_32);
+    if (gzread(fd, p, totalSize) != totalSize)
+       return NULL;
+    
+    h = headerLoad(block);
+
+    free(block);
+
+    return h;
+}
+
 /********************************************************************/
 /*                                                                  */
 /* Header loading and unloading                                     */
index cfe38b1..bd21ccf 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef H_HEADER
 #define H_HEADER
 #include <stdio.h>
+#include <zlib.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -71,6 +72,8 @@ extern const struct headerSprintfExtension headerDefaultFormats[];
 /* read and write a header from a file */
 Header headerRead(int fd, int magicp);
 void headerWrite(int fd, Header h, int magicp);
+Header headerGzRead(gzFile fd, int magicp);
+void headerGzWrite(gzFile fd, Header h, int magicp);
 unsigned int headerSizeof(Header h, int magicp);
 
 #define HEADER_MAGIC_NO   0