New "tag data" container struct + some basic methods to deal with it
- to be used for passing around header and extension data - inspired by similar changes in rpm5.org, details and implementation differ
This commit is contained in:
parent
6fd646f238
commit
a83cfce188
|
@ -65,6 +65,7 @@ pkginclude_HEADERS += lib/rpmfi.h
|
|||
pkginclude_HEADERS += lib/rpmgi.h
|
||||
pkginclude_HEADERS += lib/rpmps.h
|
||||
pkginclude_HEADERS += lib/rpmtag.h
|
||||
pkginclude_HEADERS += lib/rpmtd.h
|
||||
pkginclude_HEADERS += lib/rpmte.h
|
||||
pkginclude_HEADERS += lib/rpmts.h
|
||||
pkginclude_HEADERS += lib/rpmtypes.h
|
||||
|
|
|
@ -24,7 +24,7 @@ librpm_la_SOURCES = \
|
|||
backend/dbconfig.c backend/db3.c \
|
||||
hdrNVR.c header.c headerfmt.c header_internal.c header_internal.h \
|
||||
poptDB.c rpmhash.c rpmhash.h rpmdb.c rpmdb_internal.h \
|
||||
fprint.c fprint.h tagname.c tagtbl.c \
|
||||
fprint.c fprint.h tagname.c tagtbl.c rpmtd.c \
|
||||
cpio.c cpio.h depends.c formats.c fs.c fsm.c fsm.h \
|
||||
manifest.c manifest.h misc.c package.c \
|
||||
poptALL.c poptI.c poptQV.c psm.c psm.h query.c \
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <rpm/rpmio.h>
|
||||
#include <rpm/rpmtypes.h>
|
||||
#include <rpm/rpmtd.h>
|
||||
#include <rpm/rpmutil.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#include "system.h"
|
||||
|
||||
#include <rpm/rpmtd.h>
|
||||
#include <rpm/rpmstring.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
rpmtd rpmtdNew(void)
|
||||
{
|
||||
rpmtd td = xmalloc(sizeof(*td));
|
||||
rpmtdReset(td);
|
||||
return td;
|
||||
}
|
||||
|
||||
rpmtd rpmtdFree(rpmtd td)
|
||||
{
|
||||
/* permit free on NULL td */
|
||||
if (td != NULL) {
|
||||
/* XXX should we free data too - a flag maybe? */
|
||||
free(td);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rpmtdReset(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
|
||||
memset(td, 0, sizeof(*td));
|
||||
td->ix = -1;
|
||||
}
|
||||
|
||||
void rpmtdFreeData(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
|
||||
if (td->freeData) {
|
||||
free(td->data);
|
||||
}
|
||||
rpmtdReset(td);
|
||||
}
|
||||
|
||||
rpm_count_t rpmtdCount(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
return td->count;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#ifndef _RPMTD_H
|
||||
#define _RPMTD_H
|
||||
|
||||
#include <rpm/rpmtypes.h>
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Container for rpm tag data (from headers or extensions).
|
||||
*/
|
||||
struct rpmtd_s {
|
||||
rpmTag tag; /* rpm tag of this data entry*/
|
||||
rpmTagType type; /* data type */
|
||||
rpm_count_t count; /* number of entries */
|
||||
rpm_data_t data; /* pointer to actual data */
|
||||
int freeData; /* was data malloced */
|
||||
int ix; /* iteration index */
|
||||
};
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Create new tag data container
|
||||
* ®return New, initialized tag data container.
|
||||
*/
|
||||
rpmtd rpmtdNew(void);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Destroy tag data container.
|
||||
* @param td Tag data container
|
||||
* @return NULL always
|
||||
*/
|
||||
rpmtd rpmtdFree(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* (Re-)initialize tag data container. Contents will be zeroed out
|
||||
* and iteration index reset.
|
||||
* @param td Tag data container
|
||||
*/
|
||||
void rpmtdReset(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Free contained data. This is always safe to call as the container knows
|
||||
* if data was malloc'ed or not. Container is reinitialized.
|
||||
* @param td Tag data container
|
||||
*/
|
||||
void rpmtdFreeData(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Retrieve number of entries in the container.
|
||||
* @param td Tag data container
|
||||
* @return Number of entries in contained data.
|
||||
*/
|
||||
rpm_count_t rpmtdCount(rpmtd td);
|
||||
|
||||
#endif /* _RPMTD_H */
|
|
@ -32,6 +32,8 @@ typedef uint32_t rpm_count_t;
|
|||
typedef void * rpm_data_t;
|
||||
typedef const void * rpm_constdata_t;
|
||||
|
||||
typedef struct rpmtd_s * rpmtd;
|
||||
|
||||
typedef uint32_t rpm_color_t;
|
||||
typedef uint32_t rpm_flag_t;
|
||||
typedef int32_t rpm_tid_t;
|
||||
|
|
|
@ -90,6 +90,10 @@ include/rpm/rpmtag.h: lib/rpmtag.h include/rpm/$(dirstamp)
|
|||
$(INSTALL_DATA) $(top_srcdir)/lib/rpmtag.h include/rpm/rpmtag.h
|
||||
BUILT_SOURCES += include/rpm/rpmtag.h
|
||||
CLEANFILES += include/rpm/rpmtag.h
|
||||
include/rpm/rpmtd.h: lib/rpmtd.h include/rpm/$(dirstamp)
|
||||
$(INSTALL_DATA) $(top_srcdir)/lib/rpmtd.h include/rpm/rpmtd.h
|
||||
BUILT_SOURCES += include/rpm/rpmtd.h
|
||||
CLEANFILES += include/rpm/rpmtd.h
|
||||
include/rpm/rpmte.h: lib/rpmte.h include/rpm/$(dirstamp)
|
||||
$(INSTALL_DATA) $(top_srcdir)/lib/rpmte.h include/rpm/rpmte.h
|
||||
BUILT_SOURCES += include/rpm/rpmte.h
|
||||
|
|
Loading…
Reference in New Issue