Added headerGzRead() and headerGzWrite()
CVS patchset: 2127 CVS date: 1998/05/25 03:18:54
This commit is contained in:
parent
700837975a
commit
c39795e7df
1
CHANGES
1
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
|
||||
|
|
72
lib/header.c
72
lib/header.c
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue