diff options
author | Per Øyvind Karlsen <peroyvind@mandriva.org> | 2008-02-29 13:22:34 +0000 |
---|---|---|
committer | Per Øyvind Karlsen <peroyvind@mandriva.org> | 2008-02-29 13:22:34 +0000 |
commit | ab4cd348fe4d18afeea04fb219fa24941773ddc4 (patch) | |
tree | e89bc6953bf876e657b96643896203865bccc331 | |
parent | c2e1fb0dda6f89049e2df517277347351d6ce669 (diff) | |
download | rpmtools-ab4cd348fe4d18afeea04fb219fa24941773ddc4.tar rpmtools-ab4cd348fe4d18afeea04fb219fa24941773ddc4.tar.gz rpmtools-ab4cd348fe4d18afeea04fb219fa24941773ddc4.tar.bz2 rpmtools-ab4cd348fe4d18afeea04fb219fa24941773ddc4.tar.xz rpmtools-ab4cd348fe4d18afeea04fb219fa24941773ddc4.zip |
add support for rpm5.org
-rw-r--r-- | parsehdlist.c | 10 | ||||
-rw-r--r-- | rpm2header.c | 4 | ||||
-rw-r--r-- | rpm5compat.h | 145 |
3 files changed, 157 insertions, 2 deletions
diff --git a/parsehdlist.c b/parsehdlist.c index eb618d8..bf1162e 100644 --- a/parsehdlist.c +++ b/parsehdlist.c @@ -7,12 +7,18 @@ #include <unistd.h> #include <signal.h> #include <errno.h> -#include <rpm/rpmlib.h> -#include <rpm/header.h> +#include <stdint.h> #include <stdio.h> #include <string.h> #include <ctype.h> +#include <rpm/rpmlib.h> +#if defined(RPM_FORMAT_VERSION) && RPM_FORMAT_VERSION >= 5 +#include "rpm5compat.h" +#else +#include <rpm/header.h> +#endif + #ifndef VERSION_STRING #define VERSION_STRING "0.0" #endif diff --git a/rpm2header.c b/rpm2header.c index d8831f6..429d816 100644 --- a/rpm2header.c +++ b/rpm2header.c @@ -5,7 +5,11 @@ #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> +#include <stdint.h> #include <rpmlib.h> +#if defined(RPM_FORMAT_VERSION) && RPM_FORMAT_VERSION >= 5 +#include "rpm5compat.h" +#endif #include <rpm/rpmts.h> const char *basename(const char *f) { diff --git a/rpm5compat.h b/rpm5compat.h new file mode 100644 index 0000000..e951a2f --- /dev/null +++ b/rpm5compat.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2008 Per Øyvind Karlsen <peroyvind@mandriva.org> + * + * $Id: rpm5compat.h 237744 2008-02-28 17:15:00Z peroyvind $ + * + */ +#define RPM_NULL_TYPE 0 +#define RPM_CHAR_TYPE RPM_UINT8_TYPE +#define RPM_INT8_TYPE RPM_UINT8_TYPE +#define RPM_INT16_TYPE RPM_UINT16_TYPE +#define RPM_INT32_TYPE RPM_UINT32_TYPE + +#include <rpm/rpmevr.h> +#include <rpm/rpmio.h> +#include <rpm/pkgio.h> +#include <rpm/rpmcb.h> +#include <rpm/rpmts.h> +#include <rpm/rpmmacro.h> + +enum hMagic { + HEADER_MAGIC_NO = 0, + HEADER_MAGIC_YES = 1 +}; + + +typedef uint32_t * hTAG_t; +typedef uint32_t * hTYP_t; +typedef const void * hPTR_t; +typedef uint32_t * hCNT_t; +typedef uint32_t int_32; +typedef uint16_t uint_16; +typedef uint8_t byte; +typedef union hRET_s { + const void * ptr; + const char ** argv; + const char * str; + uint32_t * ui32p; + uint16_t * ui16p; + uint32_t * i32p; + uint16_t * i16p; + uint8_t * i8p; +} * hRET_t; + +static inline int headerGetEntry(Header h, int_32 tag, hTYP_t type, void ** p, hCNT_t c){ + HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); + int rc; + + he->tag = tag; + rc = headerGet(h, he, tag); + if (rc) { + if (type) *type = he->t; + if (p) *(void **) p = he->p.ptr; + if (c) *c = he->c; + } + return rc; +} + +static int headerAddEntry(Header h, int_32 tag, int_32 type, const void * p, int_32 c) { + HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); + + he->tag = tag; + he->t = type; + he->p.str = p; + he->c = c; + return headerPut(h, he, 0); +} + +static int headerRemoveEntry(Header h, int_32 tag) { + HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); + + he->tag = tag; + return headerDel(h, he, 0); +} + +int headerModifyEntry(Header h, int_32 tag, int_32 type, const void * p, int_32 c) { + HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); + + he->tag = tag; + he->t = type; + he->p.str = p; + he->c = c; + return headerMod(h, he, 0); + +} + +static int headerNextIterator(HeaderIterator hi, hTAG_t tag, hTYP_t type, hPTR_t * p, hCNT_t c) { + HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); + + he->tag = (rpmTag)tag; + return headerNext(hi, he, 0); +} + +static HeaderIterator headerFreeIterator(HeaderIterator hi) { + return headerFini(hi); +} + +static HeaderIterator headerInitIterator(Header h){ + return headerInit(h); +} + +void * headerFreeData(const void * data, rpmTagType type) { + if (data) { + if (type == -1 || + type == RPM_STRING_ARRAY_TYPE || + type == RPM_I18NSTRING_TYPE || + type == RPM_BIN_TYPE) + free((void *)data); + } + return NULL; +} + +static int headerWrite(void * _fd, Header h, enum hMagic magicp) { + const char item[] = "Header"; + const char * fn = NULL; + const char * msg = NULL; + rpmRC rc = rpmpkgWrite(item, _fd, h, &msg); + if (rc != RPMRC_OK) { + rpmlog(RPMLOG_ERR, "%s: %s: %s\n", fn, item, msg); + rc = RPMRC_FAIL; + } + msg = _free(msg); + return rc; +} + +static inline Header headerRead(void * _fd, enum hMagic magicp) { + const char item[] = "Header"; + Header h = NULL; + const char * fn = NULL; + const char * msg = NULL; + rpmRC rc = rpmpkgRead(item, _fd, &h, &msg); + if (rc != RPMRC_OK) { + rpmlog(RPMLOG_ERR, "%s: %s: %s\n", fn, item, msg); + rc = RPMRC_FAIL; + } + msg = _free(msg); + return h; +} + +int rpmMachineScore(int type, const char * name) { + char * platform = rpmExpand(name, "-%{_real_vendor}-%{_target_os}%{?_gnu}", NULL); + int score = rpmPlatformScore(platform, NULL, 0); + + _free(platform); + return score; +} |