Skip to content

Instantly share code, notes, and snippets.

@nikibobi
Last active April 15, 2017 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikibobi/f4351e91488736377284dafbf5ade7f9 to your computer and use it in GitHub Desktop.
Save nikibobi/f4351e91488736377284dafbf5ade7f9 to your computer and use it in GitHub Desktop.
minimalistic arch package manager
#include <stdio.h>
#include <stdlib.h>
#include <alpm.h>
#include <alpm_list.h>
int main(void) {
alpm_errno_t *err;
alpm_handle_t *alpm = alpm_initialize("/", "/var/lib/pacman/", err);
if (alpm == NULL) {
printf("%s\n", alpm_strerror(*err));
exit(EXIT_FAILURE);
}
/* get the local db */
alpm_db_t *db = alpm_get_localdb(alpm);
/* get and print all installed packages */
for (alpm_list_t *l = alpm_db_get_pkgcache(db); l; l = alpm_list_next(l)) {
alpm_pkg_t *pkg = l->data;
const char *name = alpm_pkg_get_name(pkg);
printf("%s\n", name);
}
alpm_release(alpm);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment