]> git.proxmox.com Git - wasi-libc.git/commitdiff
Fix fmemopen and friends to use the correct SEEK_* values.
authorDan Gohman <sunfish@mozilla.com>
Wed, 8 May 2019 22:14:06 +0000 (15:14 -0700)
committerDan Gohman <sunfish@mozilla.com>
Thu, 9 May 2019 16:16:38 +0000 (09:16 -0700)
WASI's values for SEEK_CUR, SEEK_SET, and SEEK_END differ from musl's
values, so fix musl code that bakes in knowledge of these values.

This fixes src/functional/memstream.c.

libc-top-half/musl/src/stdio/fmemopen.c
libc-top-half/musl/src/stdio/open_memstream.c
libc-top-half/musl/src/stdio/open_wmemstream.c

index aab13f0fff612985b7f1d3f69c99ff33c395ec30..d2a0ddb5d1e1afae55c2c7059f6d38188a52ff34 100644 (file)
@@ -26,7 +26,15 @@ fail:
                errno = EINVAL;
                return -1;
        }
+#ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values.
        base = (size_t [3]){0, c->pos, c->len}[whence];
+#else
+       base = (size_t [3]) {
+            [SEEK_SET] = 0,
+            [SEEK_CUR] = c->pos,
+            [SEEK_END] = c->len
+        }[whence];
+#endif
        if (off < -base || off > (ssize_t)c->size-base) goto fail;
        return c->pos = base+off;
 }
index a54537314f6426076bfed0ff6e46a629c5e9192b..aa502206515986ef85eb99bb4dac715965517ace 100644 (file)
@@ -29,7 +29,15 @@ fail:
                errno = EINVAL;
                return -1;
        }
+#ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values.
        base = (size_t [3]){0, c->pos, c->len}[whence];
+#else
+       base = (size_t [3]) {
+            [SEEK_SET] = 0,
+            [SEEK_CUR] = c->pos,
+            [SEEK_END] = c->len
+        }[whence];
+#endif
        if (off < -base || off > SSIZE_MAX-base) goto fail;
        return c->pos = base+off;
 }
index fffec57d1fc71b7039f06777f088a3742625de38..30ffcdfb620081f9505a889f7c255ad9fe775a3e 100644 (file)
@@ -31,7 +31,15 @@ fail:
                errno = EINVAL;
                return -1;
        }
+#ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values.
        base = (size_t [3]){0, c->pos, c->len}[whence];
+#else
+       base = (size_t [3]) {
+            [SEEK_SET] = 0,
+            [SEEK_CUR] = c->pos,
+            [SEEK_END] = c->len
+        }[whence];
+#endif
        if (off < -base || off > SSIZE_MAX/4-base) goto fail;
        memset(&c->mbs, 0, sizeof c->mbs);
        return c->pos = base+off;