void list_deps(const char *pkgname, char **pkgs, char *listed, char *check_loop, char **newpkgs, int *nrnewpkgs, int *err_cnt) { char **rb, **rbtmp; char *cp; int errcode, i, j; struct reqr_by_entry *rb_entry; struct reqr_by_head *rb_list; if (isinstalledpkg(pkgname) <= 0) return; errcode = requiredby(pkgname, &rb_list, FALSE, TRUE); if (errcode < 0) return; /* * We put rb_list into an argv style NULL terminated list, * because requiredby uses some static storage, and list_deps * is a recursive function. */ rbtmp = rb = alloca((errcode + 1) * sizeof(*rb)); if (rb == NULL) { warnx("%s(): alloca() failed", __func__); (*err_cnt)++; return; } STAILQ_FOREACH(rb_entry, rb_list, link) { *rbtmp = alloca(strlen(rb_entry->pkgname) + 1); if (*rbtmp == NULL) { warnx("%s(): alloca() failed", __func__); (*err_cnt)++; return; } strcpy(*rbtmp, rb_entry->pkgname); rbtmp++; }
int pkg_perform(char **pkgs) { char **matched, **rb, **rbtmp; int errcode, i, j; int err_cnt = 0; struct reqr_by_entry *rb_entry; struct reqr_by_head *rb_list; if (MatchType != MATCH_EXACT) { matched = matchinstalled(MatchType, pkgs, &errcode); if (errcode != 0) return 1; /* Not reached */ /* * Copy matched[] into pkgs[], because we'll need to use * matchinstalled() later on. */ if (matched != NULL) { pkgs = NULL; for (i = 0; matched[i] != NULL; i++) { pkgs = realloc(pkgs, sizeof(*pkgs) * (i + 2)); pkgs[i] = strdup(matched[i]); } pkgs[i] = NULL; } else switch (MatchType) { case MATCH_GLOB: break; case MATCH_ALL: warnx("no packages installed"); return 0; case MATCH_EREGEX: case MATCH_REGEX: warnx("no packages match pattern(s)"); return 1; default: break; } } err_cnt += sortdeps(pkgs); for (i = 0; pkgs[i]; i++) { if (Recursive == TRUE) { errcode = requiredby(pkgs[i], &rb_list, FALSE, TRUE); if (errcode < 0) { err_cnt++; } else if (errcode > 0) { /* * Copy values from the rb_list queue into argv-like NULL * terminated list because requiredby() uses some static * storage, while pkg_do() below will call this function, * thus blowing our rb_list away. */ rbtmp = rb = alloca((errcode + 1) * sizeof(*rb)); if (rb == NULL) { warnx("%s(): alloca() failed", __func__); err_cnt++; continue; } STAILQ_FOREACH(rb_entry, rb_list, link) { *rbtmp = alloca(strlen(rb_entry->pkgname) + 1); if (*rbtmp == NULL) { warnx("%s(): alloca() failed", __func__); err_cnt++; continue; } strcpy(*rbtmp, rb_entry->pkgname); rbtmp++; } *rbtmp = NULL; err_cnt += sortdeps(rb); for (j = 0; rb[j]; j++) err_cnt += pkg_do(rb[j]); }