+static int
+headissourceheuristic(RpmHead *h)
+{
+ unsigned int i, o;
+ unsigned char *d = headfindtag(h, TAG_DIRNAMES);
+ if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 8)
+ return 0;
+ o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
+ i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
+ return i == 1 && o < h->dcnt && !h->dp[o] ? 1 : 0;
+}
+
+static inline void
+headfree(RpmHead *h)
+{
+ solv_free(h);
+}
+
+#else
+
+typedef struct headerToken_s RpmHead;
+
+static int
+headexists(RpmHead *h, int tag)
+{
+ return headerIsEntry(h, tag);
+}
+
+static void *headget(RpmHead *h, int tag, int *cnt, int alloc)
+{
+ struct rpmtd_s td;
+ if (!headerGet(h, tag, &td, alloc ? HEADERGET_ALLOC : HEADERGET_MINMEM))
+ return 0;
+ if (cnt)
+ *cnt = td.count;
+ return td.data;
+}
+
+static uint32_t *
+headint32array(RpmHead *h, int tag, int *cnt)
+{
+ return headget(h, tag, cnt, 1);
+}
+
+static uint32_t
+headint32(RpmHead *h, int tag)
+{
+ uint32_t *arr = headget(h, tag, 0, 0);
+ return arr ? arr[0] : 0;
+}
+
+static uint64_t *
+headint64array(RpmHead *h, int tag, int *cnt)
+{
+ return headget(h, tag, cnt, 1);
+}
+
+/* returns the first entry of an 64bit integer array */
+static uint64_t
+headint64(RpmHead *h, int tag)
+{
+ uint64_t *arr = headget(h, tag, 0, 0);
+ return arr ? arr[0] : 0;
+}
+
+static uint16_t *
+headint16array(RpmHead *h, int tag, int *cnt)
+{
+ return headget(h, tag, cnt, 1);
+}
+
+static char *
+headstring(RpmHead *h, int tag)
+{
+ return headget(h, tag, 0, 0);
+}
+
+static char **
+headstringarray(RpmHead *h, int tag, int *cnt)
+{
+ return headget(h, tag, cnt, 1);
+}
+
+static unsigned char *
+headbinary(RpmHead *h, int tag, unsigned int *sizep)
+{
+ unsigned char *b = headget(h, tag, (int *)sizep, 0);
+ if (b && sizep && (tag == TAG_SIGMD5 || tag == SIGTAG_MD5) && *sizep > 16) {
+ /* due to a bug in rpm the count may be bigger if HEADERIMPORT_FAST is used */
+ *sizep = 16;
+ }
+ return b;
+}
+
+static int
+headissourceheuristic(RpmHead *h)
+{
+ struct rpmtd_s td;
+ int issource;
+ if (!headerGet(h, TAG_DIRNAMES, &td, HEADERGET_MINMEM))
+ return 0;
+ issource = td.count == 1 && td.data && ((char **)td.data)[0] && !((char **)td.data)[0][0];
+ rpmtdFreeData(&td);
+ return issource;
+}
+
+static inline void
+headfree(RpmHead *h)
+{
+ headerFree(h);
+}
+
+#endif
+