|Anonymous | Login | Signup for a new account||2017-09-24 10:24 UTC|
|Main | My View | View Issues | Change Log | Docs|
|Viewing Issue Simple Details|
|ID||Category||Severity||Type||Date Submitted||Last Update|
|0001152||[1003.1(2008)/Issue 7] System Interfaces||Editorial||Clarification Requested||2017-06-22 07:50||2017-06-22 07:50|
|Final Accepted Text|
|Summary||0001152: Effect of modifications to buffer underlying a memory stream|
Consider this code:
char a = "xx", b; FILE *f = fmemopen(a, 2, "r"); fread(&b, 1, 1, f); a = 'y'; fread(&b, 1, 1, f); b = '\0'; printf("b = %s\n", b);
What is the expected contents of b? I'd assume 'y', but the first fread() is there to trigger the implementation's internal buffering if it happens to do so for memory streams. And sure enough, at least with glibc the above produces "b = xx".
A setvbuf(f, NULL, _IONBF, 0) after fmemopen does make the stream behave as I'd naively expect.
fopen has the text "When opened, a stream is fully buffered if and only if it can be determined not to refer to an interactive device.", but I cannot find anything similar for fmemopen, so it's unclear whether this applies to all streams or just those created by fopen().
Clarify what one can expect when mixing fread() and direct modifications of the underlying buffer.
Clarify the effects of setvbuf() on memory streams, and in particular, the effect of _IONBF, which seems to be necessary to get the behaviour that I naively expected.
Clarify the initial buffering mode of a stream created by fmemopen().
|Tags||No tags attached.|
|There are no notes attached to this issue.|
|2017-06-22 07:50||Villemoes||New Issue|
|2017-06-22 07:50||Villemoes||Status||New => Under Review|
|2017-06-22 07:50||Villemoes||Assigned To||=> ajosey|
|2017-06-22 07:50||Villemoes||Name||=> Rasmus Villemoes|
|2017-06-22 07:50||Villemoes||Section||=> fmemopen|
|Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group|