seekable stdin (was: [Fwd: Whitelist ??])

Gyepi SAM gyepi at praxis-sw.com
Tue Dec 7 05:49:26 CET 2004


On Mon, Dec 06, 2004 at 06:03:06PM -0500, David Relson wrote:
> Reading stdin twice isn't doable, AFAIK.  I use "cat > tmp.$$" to create
> a file and then use that.

Actually reading stdin twice *is* doable, if stdin points to a seekable file.
The filter looked like it was written for postfix, which, as I recall, does
write the message to disk and dups the filter stdin to the file handle, so
stdin *should* be seekable, but it's probably not portable to depend on it.

Nonetheless, rewind(3) or seek(3) would do the trick, but the latter should be
preferred since has a return value.

In a shell script, the easy option is to say: 
 
perl -e 'seek(STDIN, 0, 0) or die "cannot seek stdin. $!\n"'

I have a C version knocking around if perl is too slow ;)

-Gyepi




More information about the Bogofilter mailing list