diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-10-11 15:19:09 -0700 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2013-02-02 16:44:15 -0800 |
commit | 653556333b87fdab40001068671f029829de6d2a (patch) | |
tree | 9839142d1a04aa9bd4fa1d3aafb879e2923c2556 /rpmqpack.c | |
parent | 8c37028da6ed96005a02f40694ef62e6b702814d (diff) | |
download | librpm-tizen-653556333b87fdab40001068671f029829de6d2a.tar.gz librpm-tizen-653556333b87fdab40001068671f029829de6d2a.tar.bz2 librpm-tizen-653556333b87fdab40001068671f029829de6d2a.zip |
Provide rpmqpack
a fast way to list all installed packages are
check if some package is installed. This is a hack.
Diffstat (limited to 'rpmqpack.c')
-rw-r--r-- | rpmqpack.c | 59 |
1 files changed, 59 insertions, 0 deletions
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 <sys/types.h> +#include <limits.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <db.h> + +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; +} |