Bug 394 - wierd I/O-error handling in libio
Summary: wierd I/O-error handling in libio
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.3.3
: P2 minor
Target Milestone: ---
Assignee: GOTO Masanori
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-20 22:10 UTC by Pavel Kankovsky
Modified: 2005-09-23 16:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
fmemopen() testcase (410 bytes, text/plain)
2004-10-07 21:07 UTC, Pavel Kankovsky
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Kankovsky 2004-09-20 22:10:40 UTC
1. {new,old}_do_write() & _IO_{new,old}_file_xsputn() cannot handle -1 from
_IO_SYSWRITE() even if -1 appears to be the expected way to signal errors (and
certain functions like fmemopen_write() do that)

2. read errors are recorded (_IO_ERR_SEEN) in _IO_{new,old}_file_overflow() and
_IO_file_xsgetn() (but not in _IO_default_xsgetn()!) while write errors are
recorded on a lower level--in _IO_{new,old}_file_write() (and this is impossible
to do with fopencookie()); are these inconsistencies intentional?
Comment 1 Ulrich Drepper 2004-09-26 12:43:32 UTC
Which _IO_SYSWRITE implementation returns -1?  Certainly not _IO_new_file_write.

And don't ask questions about the code, I have no time to answer those.  If you
think you found a problem, write a test case.
Comment 2 Pavel Kankovsky 2004-10-07 21:07:42 UTC
Created attachment 223 [details]
fmemopen() testcase

This programs creates a memory stream with a buffer 10 chars long and checks
what happens when too much data are written to it.

Case 1: 100 successful putc's, fflush after putc #100 fails, ferror not set
$ ./ts
fflush #100 failed: no err
final status: no err
INCORRECT (error detected by fflush but ferror not set)

Case 2: 100 successful putc's, no fflush, ferror not set, fclose fails
$ ./ts 100 100
final status: no err
fclose failed
CORRECT (error detected during implicit fflush in fclose)

Case 3: lots of putc's, no fflush, putc #8193 fails, ferror not set--WRONG
$ ./ts 100000 100000
putc #8193 failed: no err
final status: no err
INCORRECT (error detected by putc #8193 but ferror not set)

Any stream implemented using fopencookie() and using the documented way
(libc.info: Hook Functions) to report errors from cookie functions (return -1)
would exhibit similar errors.
Comment 3 Ulrich Drepper 2005-09-23 16:35:36 UTC
The current code on the trunk should behave correctly.