提交 22e45423 编写于 作者: R Rich Felker

fmemopen: fix eof handling, hopefully right this time

上级 f81279ff
......@@ -24,8 +24,10 @@ static size_t mread(FILE *f, unsigned char *buf, size_t len)
{
struct cookie *c = f->cookie;
size_t rem = c->size - c->pos;
if (!len) return 0;
if (len > rem) len = rem;
if (len > rem) {
len = rem;
f->flags |= F_EOF;
}
memcpy(buf, c->buf+c->pos, len);
c->pos += len;
rem -= len;
......@@ -34,7 +36,6 @@ static size_t mread(FILE *f, unsigned char *buf, size_t len)
f->rend = f->buf + rem;
memcpy(f->rpos, c->buf+c->pos, rem);
c->pos += rem;
if (!len) f->flags |= F_EOF;
return len;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册