mirror of
git://git.musl-libc.org/musl
synced 2025-02-13 09:27:23 +00:00
optimize seek function for memory streams
This commit is contained in:
parent
32d67e938e
commit
c88f36f556
@ -13,21 +13,12 @@ static off_t ms_seek(FILE *f, off_t off, int whence)
|
|||||||
{
|
{
|
||||||
ssize_t base;
|
ssize_t base;
|
||||||
struct cookie *c = f->cookie;
|
struct cookie *c = f->cookie;
|
||||||
switch (whence) {
|
if (whence>2U) {
|
||||||
case SEEK_SET:
|
|
||||||
base = 0;
|
|
||||||
break;
|
|
||||||
case SEEK_CUR:
|
|
||||||
base = c->pos;
|
|
||||||
break;
|
|
||||||
case SEEK_END:
|
|
||||||
base = c->len;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fail:
|
fail:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
base = (size_t [3]){0, c->pos, c->len}[whence];
|
||||||
if (off < -base || off > SSIZE_MAX-base) goto fail;
|
if (off < -base || off > SSIZE_MAX-base) goto fail;
|
||||||
return c->pos = base+off;
|
return c->pos = base+off;
|
||||||
}
|
}
|
||||||
|
@ -14,21 +14,12 @@ static off_t wms_seek(FILE *f, off_t off, int whence)
|
|||||||
{
|
{
|
||||||
ssize_t base;
|
ssize_t base;
|
||||||
struct cookie *c = f->cookie;
|
struct cookie *c = f->cookie;
|
||||||
switch (whence) {
|
if (whence>2U) {
|
||||||
case SEEK_SET:
|
|
||||||
base = 0;
|
|
||||||
break;
|
|
||||||
case SEEK_CUR:
|
|
||||||
base = c->pos;
|
|
||||||
break;
|
|
||||||
case SEEK_END:
|
|
||||||
base = c->len;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fail:
|
fail:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
base = (size_t [3]){0, c->pos, c->len}[whence];
|
||||||
if (off < -base || off > SSIZE_MAX/4-base) goto fail;
|
if (off < -base || off > SSIZE_MAX/4-base) goto fail;
|
||||||
memset(&c->mbs, 0, sizeof c->mbs);
|
memset(&c->mbs, 0, sizeof c->mbs);
|
||||||
return c->pos = base+off;
|
return c->pos = base+off;
|
||||||
|
Loading…
Reference in New Issue
Block a user