fix stderr, fdopen
Eric Blake
ebb9@byu.net
Mon Jul 16 12:13:00 GMT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
POSIX requires "The stderr stream is expected to be open for reading and
writing". This implements that (and if fd 2 is a write-only pipe instead
of a read-write tty, fgetc(stderr) will correctly fail later on); ok to
apply?
Also, for fdopen, POSIX states "Although not explicitly required by this
volume of IEEE Std 1003.1-2001, a good implementation of append (a) mode
would cause the O_APPEND flag to be set." OK to apply?
I'm not quite sure whether POSIX requires the following example to remain
in append mode, or if it can go to seekable writes; but I'm assuming that
a stream must remain in append mode even if the underlying fd is altered.
remove("foo");
FILE *f = fopen("foo", "a");
fputs("hi", f);
fflush(f);
fcntl(fileno(f), F_SETFL, fcntl(fileno(f), F_GETFL) & ~O_APPEND);
fseek(f, 0, SEEK_SET);
fputs("bye", f);
fclose(f);
/* Does "foo" now contain "hibye", or just "bye"? */
2007-07-13 Eric Blake <ebb9@byu.net>
More POSIX stream corner cases.
* libc/stdio/findfp.c (__sinit): Open stderr read/write.
* libc/stdio/fdopen.c (_fdopen_r): Set O_APPEND on fd when
requested.
* libc/stdio64/fdopen64.c (_fdopen64_r): Likewise.
- --
Don't work too hard, make some time for fun as well!
Eric Blake ebb9@byu.net
-----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
iD8DBQFGmDzU84KuGfSFAYARAqOUAKCERj8sP32yTUX6htEBR0WN2eu7qwCg1mLL
Nr7bxe59nWhiYNvwLBFdZGA=
=ryfS
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: newlib.patch21
URL: <http://sourceware.org/pipermail/newlib/attachments/20070716/220d3f8b/attachment.ksh>
More information about the Newlib
mailing list