This way a program reading from dpkg-query through a pipe will get the output in a single read() --- src/querycmd.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/querycmd.c b/src/querycmd.c index a39ee25..8d3ee7c 100644 --- a/src/querycmd.c +++ b/src/querycmd.c @@ -306,6 +306,7 @@ listpackages(const char *const *argv) static int searchoutput(struct filenamenode *namenode) { struct filepackages_iterator *iter; struct pkginfo *pkg_owner; + char *out, *t; int found; if (namenode->divert) { @@ -326,16 +327,34 @@ static int searchoutput(struct filenamenode *namenode) { } found= 0; + out = malloc(256); + if (!out) { + notice(_("out of memory")); + exit(1); + } + out[0] = '\0'; + iter = filepackages_iter_new(namenode); while ((pkg_owner = filepackages_iter_next(iter))) { - if (found) - fputs(", ", stdout); - fputs(pkg_name(pkg_owner, pnaw_nonambig), stdout); + if (found) { + q = strlen(out) + 2; + out = realloc(out, strlen(out) + 2); + strcat(out, ", "); + } + t = (char *) pkg_name(pkg_owner, pnaw_nonambig); + out = realloc(out, strlen(out) + strlen(t)); + strcat(out, t); found++; } filepackages_iter_free(iter); - if (found) printf(": %s\n",namenode->name); + if (found) { + out = realloc(out, strlen(out) + strlen(": ") + strlen(namenode->name)); + strcat(out, ": "); + strcat(out, namenode->name); + puts(out); + free(out); + } return found + (namenode->divert ? 1 : 0); } -- 1.8.4.rc3 -- To UNSUBSCRIBE, email to debian-dpkg-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1377902027-6188-1-git-send-email-shawnland...@gmail.com