Public Comment Number PC-UK0285 ISO/IEC CD2 9899 (SC22N2794) Public Comment =========================================== Date: 1998-12-13 Author: C.D.W.Feather Author Affiliation: Self Postal Address: Demon Internet Ltd. 322 Regents Park Road London N3 2QQ United Kingdom E-mail Address: Telephone Number: +44 181 371 1138 Fax Number: +44 181 371 1037 Category: Clarification Committee Draft subsection: 7.19.5.1 Title: Clarify meaning of a failed fclose Detailed description: If a call to fclose() fails it is not clear whether: - it is still possible to access the stream; - whether fflush(NULL) will attempt to flush the stream; - whether it is safe to destroy a buffer allocated to the stream by setvbuf(). There are two possibilities: a failed fclose can leave the stream open as far as the program is concerned, or it can leave it closed (irrespective of the state of the underlying entity). The first case is a problem if the close fails part way through, as it might not be possible to reinstate the status of the stream. Therefore the second is better, because the implementation can always carry out those parts of the cleanup that are visible to the program (such as the second and third items above). The existing wording - read strictly - also requires the full list of actions to be carried out successfully whether or not the call fails. This is clearly an oversight. Change 7.19.5.1p2 to read: A successful call to the fclose function causes the stream pointed to by stream to be flushed and the associated file to be closed. Any unwritten buffered data for the stream are delivered to the host environment to be written to the file; any unread buffered data are discarded. Whether or not the call succeeds, the stream is disassociated from the file and any buffer set by the setbuf or setvbuf function is disassociated from the stream, and if the later was automatically allocated, it is deallocated. Note that this does not require anything outside the control of the implementation to take place if the call fails, while still leaving the program in a safe state.