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

optimize seek function for memory streams

上级 32d67e93
......@@ -13,21 +13,12 @@ static off_t ms_seek(FILE *f, off_t off, int whence)
{
ssize_t base;
struct cookie *c = f->cookie;
switch (whence) {
case SEEK_SET:
base = 0;
break;
case SEEK_CUR:
base = c->pos;
break;
case SEEK_END:
base = c->len;
break;
default:
fail:
if (whence>2U) {
fail:
errno = EINVAL;
return -1;
}
base = (size_t [3]){0, c->pos, c->len}[whence];
if (off < -base || off > SSIZE_MAX-base) goto fail;
return c->pos = base+off;
}
......
......@@ -14,21 +14,12 @@ static off_t wms_seek(FILE *f, off_t off, int whence)
{
ssize_t base;
struct cookie *c = f->cookie;
switch (whence) {
case SEEK_SET:
base = 0;
break;
case SEEK_CUR:
base = c->pos;
break;
case SEEK_END:
base = c->len;
break;
default:
fail:
if (whence>2U) {
fail:
errno = EINVAL;
return -1;
}
base = (size_t [3]){0, c->pos, c->len}[whence];
if (off < -base || off > SSIZE_MAX/4-base) goto fail;
memset(&c->mbs, 0, sizeof c->mbs);
return c->pos = base+off;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册