diff options
author | ewt <devnull@localhost> | 1997-02-14 03:25:42 +0000 |
---|---|---|
committer | ewt <devnull@localhost> | 1997-02-14 03:25:42 +0000 |
commit | 62a01ab51869d05c9ad7e81eb3435580adbb9538 (patch) | |
tree | f30d00cf099dc4cf3bc5c10eded1ae981edb04c6 /lib | |
parent | 56b924a57ff685e0ca748b09a1586286d6068fbb (diff) | |
download | rpm-62a01ab51869d05c9ad7e81eb3435580adbb9538.tar.gz rpm-62a01ab51869d05c9ad7e81eb3435580adbb9538.tar.bz2 rpm-62a01ab51869d05c9ad7e81eb3435580adbb9538.zip |
added headerRemoveEntry()
CVS patchset: 1420
CVS date: 1997/02/14 03:25:42
Diffstat (limited to 'lib')
-rw-r--r-- | lib/header.c | 30 | ||||
-rw-r--r-- | lib/header.h | 3 |
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/header.c b/lib/header.c index 9ead1b5a2..4f0716ffe 100644 --- a/lib/header.c +++ b/lib/header.c @@ -853,3 +853,33 @@ int headerAppendEntry(Header h, int_32 tag, int_32 type, void * p, int_32 c) { return 0; } + +int headerRemoveEntry(Header h, int_32 tag) { + struct indexEntry * entry, * last; + + entry = findEntry(h, tag, RPM_NULL_TYPE); + if (!entry) return 1; + + /* make sure entry points to the first occurence of this tag */ + while (entry > h->index && (entry - 1)->info.tag == tag) + entry--; + + /* We might be better off just counting the number of items off the + end and issuing one big memcpy, but memcpy() doesn't have to work + on overlapping regions thanks to ANSI <sigh>. A alloca() and two + memcpy() would probably still be a win (as our moving from the + end to the middle isn't very nice to the qsort() we'll have to + do to make up for this!), but I'm too lazy to implement it. Just + remember that this repeating this is basically nlogn thanks to this + dumb implementation (but n is the best we'd do anyway) */ + + last = h->index + h->indexUsed; + while (entry->info.tag == tag && entry < last) { + *(entry++) = *(--last); + } + h->indexUsed = last - h->index; + + h->sorted = 0; + + return 0; +} diff --git a/lib/header.h b/lib/header.h index 1deb083d4..feb2d62f7 100644 --- a/lib/header.h +++ b/lib/header.h @@ -79,6 +79,9 @@ int headerGetEntry(Header h, int_32 tag, int_32 *type, void **p, int_32 *c); int headerGetRawEntry(Header h, int_32 tag, int_32 *type, void **p, int_32 *c); int headerIsEntry(Header h, int_32 tag); +/* removes all entries of type tag from the header, returns 1 if none were + found */ +int headerRemoveEntry(Header h, int_32 tag); HeaderIterator headerInitIterator(Header h); int headerNextIterator(HeaderIterator iter, |