[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
sed bug on seekable stdin
From: |
Eric Blake |
Subject: |
sed bug on seekable stdin |
Date: |
Sat, 16 Dec 2006 20:40:29 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Thunderbird/1.5.0.8 Mnenhy/0.7.4.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
POSIX requires the following behavior [1]:
$ rm -Rf file
$ echo a b | tr ' ' '\n' > file
$ (sed -n 1q; cat) < file
b
And on systems like Solaris, where exit() implicitly calls fclose(stdin),
this is the case. But on systems like Linux, where glibc does not do
this, and where Ulrich is unwilling to change glibc to help out[2], sed
fails to restore the fd's current offset to the next unprocessed byte,
meaning that cat sees EOF instead of the correct "b\n".
The solution is simple - before any use of exit(EXIT_SUCCESS) (or before
returning from main), you must ensure that you call fclose(stdin).
[1] http://www.opengroup.org/susv3xcu/xcu_chap01.html, section 1.11, input
files
[2] http://sources.redhat.com/bugzilla/show_bug.cgi?id=3746
- --
Life is short - so eat dessert first!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFhLws84KuGfSFAYARAs5RAJwK30oA1+4QTSmycFA0ZB2xsoYaKgCeOtEl
38cXzLXiSRLmmL/TTI87JdM=
=CTu8
-----END PGP SIGNATURE-----
- sed bug on seekable stdin,
Eric Blake <=
- Re: sed bug on seekable stdin, Paolo Bonzini, 2006/12/17
- Re: sed bug on seekable stdin, Eric Blake, 2006/12/17
- Re: sed bug on seekable stdin, Andreas Schwab, 2006/12/17
- Re: sed bug on seekable stdin, Eric Blake, 2006/12/17
- Re: sed bug on seekable stdin, Paul Jarc, 2006/12/17