Paul Eggert wrote: >If this is merely for debugging, can't you write a wrapper that forces >line buffering for a program? The wrapper could substitute your own C >library functions via LD_PRELOAD, or could run the program inside a >pseudotty a la 'expect'. > > No I was thinking of a more simple general solution, rather than a once off complicated hack.
>If it's for production use then I'm not sure it's a good idea to slow >down and complicate standard libraries and/or apps for a >fairly-specialized need. > > I thought it would be quite a common requirement to control stdio buffering. why does grep have the --line-buffered option for example? Usually where I notice the lack of control is in commands of the format: `intermittend_output | blah1 | blah2` where blah1 buffers things up when I don't want. The following pseudo code is what I was thinking of, to be run at the start of the appropriate applications (or ideally in glibc): for (fd=0; fd<3; fd++) { //getdtablesize maybe if ((val = getenv("BUF_%d_" % fd))) { if (fstat(fd) != 0) continue; val = atoi(val); if (val == 0) { setvbuf(fd, (char*) NULL, _IONBF, 0); } else if (val == 1) { setvbuf(fd, (char*) NULL, _IOLBF, 0); } else if (val > 1) { char* buf = malloc(val); setvbuf(fd, buf, _IOFBF, val); } } } thanks, Pádraig. _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils