提交 f66022dd 编写于 作者: R Rich Felker

make fmemopen's w+ mode truncate the buffer

the w+ mode is specified to "truncate the buffer contents". like most
of fmemopen, exactly what this means is underspecified. mode w and w+
of course implicitly 'truncate' the buffer if a write from the initial
position is flushed, so in order for this part of the text about w+
not to be spurious, it should be interpreted as requiring something
else, and the obvious reasonable interpretation is that the truncation
is immediately visible if you attempt to read from the stream or the
buffer before writing/flushing.

this interpretation agrees with reported conformance test failures.
上级 b39b47ba
......@@ -112,6 +112,7 @@ FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode)
if (!plus) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD;
if (*mode == 'r') f->c.len = size;
else if (*mode == 'a') f->c.len = f->c.pos = strnlen(buf, size);
else if (plus) *f->c.buf = 0;
f->f.read = mread;
f->f.write = mwrite;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册