aboutsummaryrefslogtreecommitdiffstats
path: root/rpm-find-leaves.c
diff options
context:
space:
mode:
authorChmouel Boudjnah <chmouel@mandriva.org>2000-02-17 17:58:25 +0000
committerChmouel Boudjnah <chmouel@mandriva.org>2000-02-17 17:58:25 +0000
commitec103b683b1679b09e1d1a54b14a4ba178d67a37 (patch)
treebaeb8862d2fbee36aa6c58c282a3383c9aeb7c4c /rpm-find-leaves.c
parent30066bc80a46d6b873549c8d6b31e426195ecfbe (diff)
downloadrpmtools-ec103b683b1679b09e1d1a54b14a4ba178d67a37.tar
rpmtools-ec103b683b1679b09e1d1a54b14a4ba178d67a37.tar.gz
rpmtools-ec103b683b1679b09e1d1a54b14a4ba178d67a37.tar.bz2
rpmtools-ec103b683b1679b09e1d1a54b14a4ba178d67a37.tar.xz
rpmtools-ec103b683b1679b09e1d1a54b14a4ba178d67a37.zip
Initial revisioncookertopic/MandrakeSoft
Diffstat (limited to 'rpm-find-leaves.c')
-rw-r--r--rpm-find-leaves.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/rpm-find-leaves.c b/rpm-find-leaves.c
new file mode 100644
index 0000000..c72337a
--- /dev/null
+++ b/rpm-find-leaves.c
@@ -0,0 +1,49 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <rpm/rpmlib.h>
+#include <rpm/header.h>
+
+static Header header;
+
+#define die(f) { perror(f); exit(1); }
+
+rpmdb open_rpmdb(void) {
+ rpmdb db;
+ if (rpmdbOpen("", &db, O_RDONLY, 0644)) die("rpmdbOpen");
+ return db;
+}
+
+char *get(int_32 tag) {
+ int_32 type, count;
+ char *s;
+ if (headerGetEntry(header, tag, &type, (void **) &s, &count) != 1) die("bad header ??");
+ return s;
+}
+
+
+int main() {
+ rpmTransactionSet trans;
+ struct rpmDependencyConflict *conflicts;
+ int numConflicts;
+ rpmdb db;
+ int i;
+
+ rpmReadConfigFiles(NULL, NULL);
+
+ db = open_rpmdb();
+
+ for(i = rpmdbFirstRecNum(db); i; i = rpmdbNextRecNum(db, i)) {
+ trans = rpmtransCreateSet(db, NULL);
+ rpmtransRemovePackage(trans, i);
+ if (rpmdepCheck(trans, &conflicts, &numConflicts)) die("rpmdepCheck");
+ if (numConflicts == 0) {
+ header = rpmdbGetRecord(db, i);
+ printf("%s-%s-%s\n", get(RPMTAG_NAME), get(RPMTAG_VERSION), get(RPMTAG_RELEASE));
+ headerFree(header);
+ }
+ rpmdepFreeConflicts(conflicts, numConflicts);
+ rpmtransFree(trans);
+ }
+ exit(0);
+}