IEEE Std 1003.1-2001-02 Interpretation #2

Copyright © 2006 IEEE. All rights reserved.

Topic: interaction of file descriptors and I/O streams
	Relevant Sections:	2.5.1
------------------------------------------------------------------------ 
 7  Defect Report concerning (number and title of International Standard
    or DIS final text, if applicable): 
The System Interfaces Volume of IEEE Std 1003.1-2001
------------------------------------------------------------------------ 
 8  Qualifier (e.g. error, omission, clarification required):
1: Error
------------------------------------------------------------------------ 
 9  References in document (e.g. page, clause, figure, and/or table
    numbers):
Page: 36  Line: 1472  Section: 2.5.1
XSH Enhancement Request Number 4
------------------------------------------------------------------------ 
10  Nature of defect (complete, concise explanation of the perceived
    problem):
 Defect code :  1. Error
 This could be filed as an error in this section or an ommision in
 fflush().
 The problem is that in section 2.5.1 of XSH, which deals with the
 interaction of file descriptors and I/O streams, it is written:
   If the stream is open with a mode that allows reading and the
   underlying open file description refers to a device that is capable of
   seeking, the application shall either perform an fflush( ), or the
   stream shall be closed.
 The man page for fflush() explicitly does not mention what happens if
 fflush() is applied to an input stream or an update stream with the last
 operation being input.  This wording comes straight from ISO C.
 The problem is that ISO C does not have to deal with file descriptors.
 POSIX does.  In the early POSIX versions the text in section 2.5.1 was
 added to make clear how the interaction works.  But the fflush()
 documentation was never updated.
------------------------------------------------------------------------ 
11  Solution proposed by the submitter (optional):
 There are two possible options:
 - the original intend was to define fflush() on input streams and it
   was just forgotten to update the fflush() documentation.  In this
   case the page should be updated with the following in line 11607
   (CX shaded):
     If /stream/ points to an input stream or an update stream in which
     the most recent operation was not input, fflush() shall cause
     all buffered input to be discarded and on seekable files the file
     offset for the file descriptor be reset to the first unprocessed
     byte.
 - if fflush() is not meant or cannot be changed some other mechanism
   for synchronizing input streams must be found.  As far as I can see
   no existing function fits the bill so I cannot make any concrete
   proposal.
------------------------------------------------------------------------ 
Interpretation response
------------------------
The standards states the requirements for fflush() and interaction
between file descriptors in section 2.5.1 . However, concerns have been raised
about this which are being referred to the sponsor.
Rationale
-------------
The standard developers noted that action is a future revision
should be to restore the wording to that of the
original 1003.1-1988 standard in fflush() and fclose().
Notes to the Editor (not part of this interpretation):
-----------------------------------------------------------
For a future revision:
Add to fflush() as a new para at the end of DESCRIPTION:
[CX shading on]
For a stream open for reading, if the file is not already at EOF, and the
file is one capable of seeking, the file offset of the underlying open file
description shall be adjusted so that the next operation on the open file
description deals with the byte after the last one read from, or written to,
the stream being flushed.
[CX shading off]
Add to fclose() as a new third paragraph in DESCRIPTION
[CX shading on]
If the file is not already at EOF, and the file is one capable of
seeking, the file offset of the underlying open file description
shall be adjusted so that the next operation on the open
file description deals with the byte after the last one read from
or written to the stream being closed.
[CX shading off]

Back to IEEE Standards Interpretations for IEEE Std 1003.1-2001