[Top][All Lists]

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

[PATCH] sed unbuffered

From: Roger Luethi
Subject: [PATCH] sed unbuffered
Date: Fri, 3 May 2002 02:01:57 +0200
User-agent: Mutt/1.3.27i

The current sed buffers input and output. Exceptions are made for input if
it is a tty [1] and for output if we are writing to a file. For instance,
if sed is reading from a pipe, it will hang on fread(3) until the input
buffer is filled or EOF occurs [2].

There is no direct way to change a stream (say, a log file) using sed and
look at the output while it happens. I have hit that problem recently in
some glibc shell code and found no elegant solution, only work-arounds.

I have written a small patch against sed 3.02. It adds a new option -u (or
--unbuffered), code and documentation. The patched sed will behave exactly
as the old one, except that the help text is slightly longer (test case
changed to reflect that) unless that specific option is provided. After
applying the patch, make check passes. I tried to change as little code as
possible, which is why I didn't make any attempts to write a faster version
bypassing streams (using read/write instead). I don't expect people who use
-u to care about performance anyway.

If have seen quite a few newsgroups postings from people looking for this
kind of functionality, so I think it should be worth it. The added code is
very small and can't possibly break anything(TM).

Please consider adding this to GNU sed.


[1] Provided the OS supports isatty(3). This allows for interactive use
    as long as you type/paste input after sed started.

[2] The comment above read_pattern_space() "Read in the next line of input"
    is misleading. For pipes, for instance, sed waits to read a 8192 bytes
    block unless the other program terminates before that.

It is well to remember that the entire universe, with one trifling
exception, is composed of others.

Attachment: sed.diff
Description: Text document

reply via email to

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