[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: controlling stdio buffering

From: Pádraig Brady
Subject: Re: controlling stdio buffering
Date: Thu, 23 Mar 2006 10:26:33 +0000
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051013)

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

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);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]