From 359baa2831dd1850cba3a1cc8d31aebf883a5138 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 30 Nov 2011 09:37:49 +0200 Subject: Add an enhanced interface for unloading, aka exporting, headers - Most callers need the size of the blob as well, which the unloader internals know perfectly well but the interface doesn't support passing it. So callers were forced to make a second call to headerSizeof() to recalculate the size. Duh. - Rename and export doHeaderUnload() as headerExport(), update internal callers to use the new name. headerExport() is hopefully a bit more obvious as a name than headerUnload() which doesn't actually undo the effect of headerLoad() for that header, but merely exports the data by serializing into on-disk format. - Header size is not size_t really, its capped to fixed much lower size. Use unsigned int to better match reality. --- lib/header.c | 22 ++++++++-------------- lib/header.h | 9 +++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/header.c b/lib/header.c index 403084bad..a0b392ae6 100644 --- a/lib/header.c +++ b/lib/header.c @@ -461,13 +461,7 @@ static int regionSwab(indexEntry entry, int il, int dl, return dl; } -/** \ingroup header - * doHeaderUnload. - * @param h header - * @retval *lengthPtr no. bytes in unloaded header blob - * @return unloaded header blob (NULL on error) - */ -static void * doHeaderUnload(Header h, size_t * lengthPtr) +void * headerExport(Header h, unsigned int *bsize) { int32_t * ei = NULL; entryInfo pe; @@ -677,8 +671,8 @@ static void * doHeaderUnload(Header h, size_t * lengthPtr) if ((((char *)ei)+len) != te) goto errxit; - if (lengthPtr) - *lengthPtr = len; + if (bsize) + *bsize = len; headerSort(h); @@ -691,7 +685,7 @@ errxit: void * headerUnload(Header h) { - return doHeaderUnload(h, NULL); + return headerExport(h, NULL); } /** @@ -908,8 +902,8 @@ errxit: Header headerReload(Header h, rpmTagVal tag) { Header nh; - size_t uc = 0; - void * uh = doHeaderUnload(h, &uc); + unsigned int uc = 0; + void * uh = headerExport(h, &uc); h = headerFree(h); if (uh == NULL) @@ -993,10 +987,10 @@ exit: int headerWrite(FD_t fd, Header h, int magicp) { ssize_t nb; - size_t length; + unsigned int length; void * uh; - uh = doHeaderUnload(h, &length); + uh = headerExport(h, &length); if (uh == NULL) return 1; switch (magicp) { diff --git a/lib/header.h b/lib/header.h index fdd6c9999..d5c7a616e 100644 --- a/lib/header.h +++ b/lib/header.h @@ -87,11 +87,20 @@ int headerVerifyInfo(int il, int dl, const void * pev, void * iv, int negate); /** \ingroup header * Convert header to on-disk representation. + * @deprecated Use headerExport() instead * @param h header (with pointers) * @return on-disk header blob (i.e. with offsets) */ void * headerUnload(Header h); +/** \ingroup header + * Export header to on-disk representation. + * @param h header (with pointers) + * @retval bsize on-disk header blob size in bytes + * @return on-disk header blob (i.e. with offsets) + */ +void * headerExport(Header h, unsigned int * bsize); + /** \ingroup header * Convert header to on-disk representation, and then reload. * This is used to insure that all header data is in one chunk. -- cgit v1.2.3