From 653556333b87fdab40001068671f029829de6d2a Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 11 Oct 2012 15:19:09 -0700 Subject: Provide rpmqpack a fast way to list all installed packages are check if some package is installed. This is a hack. --- rpmqpack.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 rpmqpack.c (limited to 'rpmqpack.c') diff --git a/rpmqpack.c b/rpmqpack.c new file mode 100644 index 000000000..731e35a44 --- /dev/null +++ b/rpmqpack.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include +#include + +#include + +DBT key; +DBT data; + +int +main(int argc, char **argv) +{ + DB *db = 0; + DBC *dbc = 0; + int ret = 0; + + if (db_create(&db, 0, 0)) + { + perror("db_create"); + exit(1); + } + if (db->open(db, 0, "/var/lib/rpm/Name", 0, DB_UNKNOWN, DB_RDONLY, 0664)) + { + perror("db->open"); + exit(1); + } + if (argc == 1) + { + if (db->cursor(db, NULL, &dbc, 0)) + { + perror("db->cursor"); + exit(1); + } + while (dbc->c_get(dbc, &key, &data, DB_NEXT) == 0) + printf("%*.*s\n", (int)key.size, (int)key.size, (char *)key.data); + dbc->c_close(dbc); + } + else + { + argc--; + while (argc--) + { + argv++; + key.data = (void *)*argv; + key.size = strlen(*argv); + data.data = NULL; + data.size = 0; + if (db->get(db, 0, &key, &data, 0) == 0) + printf("%s\n", *argv); + else + ret = 1; + } + } + db->close(db, 0); + return ret; +} -- cgit v1.2.3