Anonymous | Login | 2024-03-28 12:49 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||
ID | Category | Severity | Type | Date Submitted | Last Update | ||
0000480 | [1003.1(2008)/Issue 7] System Interfaces | Objection | Error | 2011-07-28 15:08 | 2019-06-10 08:55 | ||
Reporter | eblake | View Status | public | ||||
Assigned To | ajosey | ||||||
Priority | normal | Resolution | Accepted As Marked | ||||
Status | Closed | ||||||
Name | Eric Blake | ||||||
Organization | Red Hat | ||||||
User Reference | ebb.handles | ||||||
Section | 2.5.1 Interaction of File Descriptors and Standard I/O Streams | ||||||
Page Number | 491 | ||||||
Line Number | 16844 | ||||||
Interp Status | Approved | ||||||
Final Accepted Text | See Note: 0000894 | ||||||
Summary | 0000480: freopen, fclose effect on multiple file handles | ||||||
Description |
The standard states that freopen always closes a handle and creates a stream that is open to a new file description when describing the interaction of freopen with handles, but later states that freopen with a NULL filename argument may (but not must) reuse the existing stream and underlying file description [XSH freopen lines 30885-89]. Here, I argue that the freopen description is intended, and that the multiple-handle text should be fixed to be made consistent. Also, the following example of two handles should be well-defined, but is currently handled differently in Solaris than it is in glibc 2.14; I argue that the glibc behavior is a bug in trying to implement 0000087 (that is, in trying to fix fclose() vs. ungetc() semantics in glibc bug http://sourceware.org/bugzilla/show_bug.cgi?id=12724, [^] glibc inadvertently also broke fclose() to blindly reposition the file description even if the stream was not otherwise used): const char buf[] = "hello world"; int fd; int fd2; FILE *f; /* Prepare a seekable file. */ fd = open (NAME, O_RDWR | O_CREAT | O_TRUNC, 0600); assert (0 <= fd); assert (write (fd, buf, sizeof buf) == sizeof buf); assert (lseek (fd, 1, SEEK_SET) == 1); /* Create an output stream visiting the file; when it is closed, all other file descriptors visiting the file must see the new file position. */ fd2 = dup (fd); assert (0 <= fd2); f = fdopen (fd2, "w"); // POSIX requires that f be at position 1 assert (f); assert(lseek(fd, 4, SEEK_SET) == 4); // fd is now the active handle assert (fclose (f) == 0); // The f/fd2 handle was never repositioned or made active assert (lseek (fd, 0, SEEK_CUR) == 4); // so fd should still be at 4 Solaris passed this test, but glibc 2.14 ended up repositioning the file description to offset 1, which was then observable in fd and causes the assertion to fail. I think the intent of the standard is clear, but recent wording changes to fclose() mean that we can make this more explicit. |
||||||
Desired Action |
At line 16844 [XSH 2.5.1], change: A handle which is a stream is considered to be closed when either an fclose( ) or freopen( ) is executed on it (the result of freopen( ) is a new stream, which cannot be a handle on the same open file description as its previous value), to: A handle which is a stream is considered to be closed when either an fclose( ), or freopen( ) with non-null filename, is executed on it (for freopen( ) with a null filename, it is implementation-defined whether a new handle is created or the existing one reused), At line 16880, add a bullet for the second handle: • If fclose( ) is the first (and only) action on the second handle, then the offset of the file description shall not be changed from what it was via the first handle. |
||||||
Tags | tc2-2008 | ||||||
Attached Files | |||||||
|
Relationships | |||||||||||
|
Issue History | |||
Date Modified | Username | Field | Change |
2011-07-28 15:08 | eblake | New Issue | |
2011-07-28 15:08 | eblake | Status | New => Under Review |
2011-07-28 15:08 | eblake | Assigned To | => ajosey |
2011-07-28 15:08 | eblake | Name | => Eric Blake |
2011-07-28 15:08 | eblake | Organization | => Red Hat |
2011-07-28 15:08 | eblake | User Reference | => ebb.handles |
2011-07-28 15:08 | eblake | Section | => 2.5.1 Interaction of File Descriptors and Standard I/O Streams |
2011-07-28 15:08 | eblake | Page Number | => 491 |
2011-07-28 15:08 | eblake | Line Number | => 16844 |
2011-07-28 15:08 | eblake | Interp Status | => --- |
2011-07-28 16:22 | jim_pugsley | Interp Status | --- => Pending |
2011-07-28 16:22 | jim_pugsley | Status | Under Review => Interpretation Required |
2011-07-28 16:22 | jim_pugsley | Resolution | Open => Accepted As Marked |
2011-07-28 16:27 | jim_pugsley | Note Added: 0000894 | |
2011-07-28 16:27 | jim_pugsley | Tag Attached: tc2-2008 | |
2011-07-28 16:29 | jim_pugsley | Final Accepted Text | => See Note: 0000894 |
2011-07-28 16:31 | eblake | Relationship added | related to 0000087 |
2011-08-10 15:19 | ajosey | Interp Status | Pending => Proposed |
2011-08-10 15:19 | ajosey | Note Added: 0000927 | |
2011-09-12 15:21 | ajosey | Interp Status | Proposed => Approved |
2011-09-12 15:21 | ajosey | Note Added: 0000959 | |
2013-02-21 18:04 | eblake | Relationship added | related to 0000662 |
2019-06-10 08:55 | agadmin | Status | Interpretation Required => Closed |
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |