Hi! [ Given the three variants, maybe this was sent by accident? Anyway. ]
On Fri, 2013-08-30 at 15:29:24 -0700, Shawn Landden wrote: > This way a program reading from dpkg-query through a pipe will get the > output in a single read() It would be good to know the motivation behind this. I'm guessing you are finding some severe performance problem when dealing with the output? But I'd not merge something in this specific form, because it complicates the code unnecessarily, and it's not using the available interfaces (like ohshit[e], m_malloc, m_realloc, varbuf, etc) which avoid problems found here such as memory leaks, unperformant string handling (strcat), etc. In any case I guess what you actually wanted might be something like the attached patch, which switches stdout to be fully buffered in case it's not a tty. If that'd help I guess I could consider adding code like that to all commands, although conversely the problem then is that programs reading from a pipe will not be able to process lines as they come, and will stall on full buffers instead which might also slow down the pipeline. Thanks, Guillem
From 3378356d01b10598729ad7329ec9d5a7b7b693e2 Mon Sep 17 00:00:00 2001 From: Guillem Jover <[email protected]> Date: Sat, 31 Aug 2013 03:20:33 +0200 Subject: [PATCH] dpkg-query: Use fully buffered output on non-tty --- src/querycmd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/querycmd.c b/src/querycmd.c index 51bcb9a..3e26a4e 100644 --- a/src/querycmd.c +++ b/src/querycmd.c @@ -873,7 +873,10 @@ int main(int argc, const char *const *argv) { if (!cipaction) badusage(_("need an action option")); - setvbuf(stdout, NULL, _IONBF, 0); + if (isatty(STDOUT_FILENO)) + setvbuf(stdout, NULL, _IONBF, 0); + else + setvbuf(stdout, NULL, _IOFBF, 0); filesdbinit(); ret = cipaction->action(argv); -- 1.8.4

