[Rpm-maint] [rpm-software-management/rpm] Is there any proper documentation with examples for librpm 6.x? (Discussion #4168)
3millionminds
notifications at github.com
Mon Mar 30 10:03:52 UTC 2026
Not ideal, but thanks.
Here's a full example for anyone else looking for a pure C implementation.
May not be 100% correct since C isn't my thing exactly but it works just like `rpm -qa` would.
```c
#include <rpm/rpmts.h>
#include <rpm/rpmdb.h>
// #include <rpm/header.h>
#include <rpm/rpmcli.h>
#include <stdio.h>
#include <fcntl.h>
int main(void)
{
rpmReadConfigFiles(NULL, NULL);
rpmts ts = rpmtsCreate();
if (!ts) {
fprintf(stderr, "Failed to create rpmts\n");
return 1;
}
/* Open DB in read-only mode */
if (rpmtsOpenDB(ts, O_RDONLY) != 0) {
fprintf(stderr, "Failed to open RPM database\n");
rpmtsFree(ts);
return 1;
}
/* NULL keyp == sequential iteration over all installed packages */
rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
if (!mi) {
fprintf(stderr, "Failed to create match iterator\n");
rpmtsFree(ts);
return 1;
}
Header h;
while ((h = rpmdbNextIterator(mi)) != NULL) {
const char *name = headerGetString(h, RPMTAG_NAME);
const char *epoch = headerGetString(h, RPMTAG_EPOCH);
const char *version = headerGetString(h, RPMTAG_VERSION);
const char *release = headerGetString(h, RPMTAG_RELEASE);
if (name && version && release)
printf("%s-%s-%s-%s\n", name, epoch, version, release);
}
/* Cleanup */
rpmdbFreeIterator(mi);
rpmtsFree(ts);
return 0;
}
```
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/discussions/4168#discussioncomment-16379080
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/repo-discussions/4168/comments/16379080 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20260330/89e5c200/attachment-0001.htm>
More information about the Rpm-maint
mailing list