Austin Group Defect Tracker

Aardvark Mark III


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001225 [1003.1(2016)/Issue7+TC2] System Interfaces Editorial Clarification Requested 2019-01-12 20:39 2019-10-07 15:17
Reporter osoong View Status public  
Assigned To
Priority normal Resolution Accepted As Marked  
Status Interpretation Required  
Name Oliver Soong
Organization
User Reference
Section fseek, fsetpos
Page Number 957-961
Line Number 32543-32545, 32575, 32584, 32670
Interp Status Proposed
Final Accepted Text Note: 0004392
Summary 0001225: flushing while seeking on memory buffer streams
Description fseek(), fseeko(), and fsetpos() apply to streams opened with fmemopen(), open_memstream(), and open_wmemstream(). fseek() and fseeko() are required to write unwritten buffered data to the underlying file. Does this mandated flushing behavior apply to memory streams? If so, the verbiage around lines 32543-32545 might need some clarification. Regardless of whether the flushing is mandated, I think some error codes should be added since flushing may still occur. It might also be helpful to add the memory buffer functions under "See Also".

Modifying lines 32543-32545 to apply to both files and memory buffer streams while still being clear is a bit tricky. I think it's easier to modify line 32543 to begin, "If the stream is backed by a file and is writable, and buffered data...". Then, at line 32545, add "If the stream was created by fmemopen(), open_memstream(), or open_wmemstream(), and if the stream is writable, and if data in the stream's I/O buffer had not been written to the underlying memory buffer, fseek() shall cause the unwritten data to be written to the underlying memory buffer."

I also think there should be entries for ENOSPC and ENOMEM errors similar to those given for fflush() (page 859, lines 28982-28985). If flushing memory streams is mandated, then they should be "shall fail" errors (page 958, line 32575), and if flushing is not mandated, then "may fail" would be more appropriate (page 958, line 32584). For reference, the errors are:


[ENOMEM] The underlying stream was created by open_memstream() or open_wmemstream() and insufficient memory is available.
[ENOSPC] There was no free space remaining on the device containing the file or in the buffer used by the fmemopen() function.


There is no explicit requirement that fsetpos() write unwritten buffered data in either the C or POSIX standard. Although the C99 rationale is not formally part of the standard, it does state that fsetpos() "assure[s] that the I/O buffer has been flushed" (7.19.5.3). I'm not sure what exactly should be done there. Perhaps add "may fail" entries at page 961 line 32670?

Finally, it might also be useful to add entries for fmemopen(), open_memstream(), and open_wmemstream() under the See Also heading at page 958 line 32595 for fseek() and fseeko() and maybe at page 961 line 32681 for fsetpos().
Desired Action page 957, line 32543: Replace "If the stream is writable and..." with "If the stream is backed by a file and is writable, and...".

page 957, line 32545: Append "If the stream was created by fmemopen(), open_memstream(), or open_wmemstream(), and if the stream is writable, and if data in the stream's I/O buffer had not been written to the underlying memory buffer, fseek() shall cause the unwritten data to be written to the underlying memory buffer."

Copy the ENOMEM and ENOSPC entries from fflush() (page 859, lines 28982-28985) to fseek() and fseeko(), either as "shall fail" errors (page 958, line 32575) or as "may fail errors (page 958, line 32584).

page 958, line 32595: Add fmemopen(), open_memstream(), and open_wmemstream() under the "See Also" heading.

page 960, line 32670: Maybe copy the same entries to fsetpos() as "may fail" errors.

page 961, line 32681: Maybe add fmemopen(), open_memstream(), and open_wmemstream() under the "See Also" heading.
Tags tc3-2008
Attached Files

- Relationships

-  Notes
(0004392)
geoffclare (manager)
2019-05-13 15:45

Interpretation response
------------------------

The standard does not speak to this issue, and as such no conformance distinction can be made between alternative implementations based on this.
This is being referred to the sponsor.

Rationale:
-------------
The fseek() description was not updated when fmemopen(), open_memstream() and open_wmemstream() were added to the standard.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------                     

On page 957 line 32543 section fseek(), change:
If the stream is writable and...
to:
If the stream has an underlying file description and is writable, and...

On page 957 line 32545 section fseek(),  append:
If the stream was created by fmemopen(), open_memstream(), or open_wmemstream() and the stream is writable, and if the stream is buffered and data in the stream's buffer has not been written to the underlying memory buffer, fseek() shall cause the unwritten data to be written to the underlying memory buffer.

On page 958 line 32568 section fseek(), change:
[EINVAL]
The whence argument is invalid. The resulting file-position indicator would be set to a negative value.
to:
[EINVAL]
The whence argument is invalid, the resulting file-position indicator would be set to a negative value, or the stream was created by fmemopen() and the resulting file-position indicator would be beyond the end of the underlying memory buffer.

On page 958 line 32575 section fseek(), change:
[ENOSPC]
There was no free space remaining on the device containing the file.
to:
[ENOMEM]
The stream was created by open_memstream() or open_wmemstream() and insufficient memory is available.


[ENOSPC]
There was no free space remaining on the device containing the file or in the buffer used by the fmemopen() function.

On page 958 line 32568 section fseek(), change the RATIONALE from:
None.
to:
When the stream was created by fmemopen(), fseek() fails if an attempt is made to seek beyond the end of the underlying memory buffer. This is different than fseek() on a file when a file size limit is in effect because the size specified to fmemopen() is a fixed, absolute limit whereas a file size limit is artificial and can be changed. With a file size limit, it is possible to seek past the limit, then raise the limit and successfully write at the new position; there is no equivalent possibility with the buffer size specified to fmemopen().

On page 958 line 32595 section fseek(),  add fmemopen() and open_memstream() under the "See Also" heading.

On page 960 line 32641 section fsetpos(), add:
[CX]If the stream has an underlying file description and is writable, and buffered data has not been written to the underlying file, fsetpos() shall cause the unwritten data to be written to the file and shall mark the last data modification and last file status change timestamps of the file for update.

If the stream was created by fmemopen(), open_memstream(), or open_wmemstream() and the stream is writable, and if the stream is buffered and data in the stream's buffer has not been written to the underlying memory buffer, fsetpos() shall cause the unwritten data to be written to the underlying memory buffer.[/CX]

On page 960 line 32665 section fsetpos(), change:
[ENOSPC]
There was no free space remaining on the device containing the file.
to:
[ENOMEM]
The stream was created by open_memstream() or open_wmemstream() and insufficient memory is available.


[ENOSPC]
There was no free space remaining on the device containing the file or in the buffer used by the fmemopen() function.

On page 961 line 32677 section fsetpos(), change RATIONALE from:
None.
to:
The ERRORS section does not include an [EINVAL] error equivalent to the one for fseek() because applications are required to obtain the fpos_t value using fgetpos(), in which case the file position to be set will always be valid. Directly manipulating the fpos_t object to set a position results in undefined behavior.  However, if an implementation detects that the requested file position would be a negative value, or would be beyond the end of the underlying memory buffer of a stream that was created by fmemopen(), it is recommended that fsetpos() returns a non-zero value and sets errno to [EINVAL].

On page 961 line 32681 section fsetpos(), add fmemopen() and open_memstream() under the "See Also" heading.        
(0004609)
agadmin (administrator)
2019-10-07 15:17

Interpretation proposed: 7 October 2019

- Issue History
Date Modified Username Field Change
2019-01-12 20:39 osoong New Issue
2019-01-12 20:39 osoong Name => Oliver Soong
2019-01-12 20:39 osoong Section => fseek, fsetpos
2019-01-12 20:39 osoong Page Number => 957-961
2019-01-12 20:39 osoong Line Number => 32543-32545, 32575, 32584, 32670
2019-05-13 15:45 geoffclare Note Added: 0004392
2019-05-13 15:46 geoffclare Interp Status => Pending
2019-05-13 15:46 geoffclare Final Accepted Text => Note: 0004392
2019-05-13 15:46 geoffclare Status New => Interpretation Required
2019-05-13 15:46 geoffclare Resolution Open => Accepted As Marked
2019-05-13 15:47 geoffclare Tag Attached: tc3-2008
2019-10-07 15:17 agadmin Interp Status Pending => Proposed
2019-10-07 15:17 agadmin Note Added: 0004609


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker