diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-29 16:09:56 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-29 16:25:31 +0100 |
| commit | 93a202d1fa6cd05b494bbf7175d79c6da075f333 (patch) | |
| tree | a78f1657bd7dfce1ea5de30f0cf9cedfdc5aff2a /tools | |
| parent | d17db29f66214b478fca83c34eb96cc5e0fbdbe2 (diff) | |
Prebuild System Files
In order to make it easier to build `picow` on systems _without_
PICO-8 support (which what this project targets...), we added a
system for producing a `system.tar.gz` tarball that contains the
generated system source required for building PICO-w (namely, the
`pico8.wasm` transpiled to C, and the `sysroot` with the embedded
data files needed by the application).
I also moved away from `a b c: ...` style recipes, as they run
multiple times in parallelized builds. I made it compatible with
older `make`s, and it will hopefully generally work.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/extract-data-pod.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/extract-data-pod.c b/tools/extract-data-pod.c index 50beadc..9a7bbdb 100644 --- a/tools/extract-data-pod.c +++ b/tools/extract-data-pod.c @@ -27,7 +27,10 @@ int main(int argc, char *argv[argc + 1]) { FILE *f = fopen(argv[1], "r"); check(f, "fopen(input)"); - char buffer[1024 * 1024]; + // 1 MiB is quite large for the stack, we also assume that the data.pod + // lives entirely within the first part of the file. This is true for the + // current version, and we can change this if it ever changes. + static char buffer[1024 * 1024]; size_t n = fread(buffer, 1, sizeof(buffer) - 1, f); check(n, "fread(input)"); buffer[n] = '\0'; @@ -46,16 +49,20 @@ int main(int argc, char *argv[argc + 1]) { for (char *s = strtok(start, sep); s; s = strtok(NULL, sep)) { long b = strtol(s, &s, 10); - ensure(b < 256 && *s == '\0', "failed to read byte"); + ensure(b >= 0 && b < 256 && *s == '\0', "failed to read byte"); + ensure((size_t)(dataptr - data) < sizeof(data), "data pod too large"); *(dataptr++) = (uint8_t)b; } } + size_t datalen = (size_t)(dataptr - data); + ensure(datalen, "failed to decode data.pod"); + FILE *o = fopen(argv[2], "wb"); check(o, "fopen(output)"); - size_t datalen = (size_t)(dataptr - data); check(datalen == fwrite(data, 1, datalen, o), "fwrite(output)"); + check(!fclose(o), "fclose(output)"); return EXIT_SUCCESS; } |
