From 58d5cf1c2702a38ba7d471c9a37dcbffe2565541 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sat, 16 Jan 2021 12:32:54 -0800 Subject: [PATCH] Link zipos into NESEMU1 A regression occurred where LIBC_ZIPOS support wasn't being properly linked into Cosmopolitan NESEMU1. Main modules that link zip support need to have the following declaration to guaranteed zip: polyfills: STATIC_YOINK("zip_uri_support"); Doing that, means system calls such as open(), mmap(), fstat(), etc. will do the right thing when encountering zip: prefixed URLs. Please also note that in the near future we're going to change it to zip:// after more closely examining the relevant URI RFCs. Fixes #28 Closes #29 Thanks @nikhedonia for the report! --- examples/nesemu1.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/nesemu1.cc b/examples/nesemu1.cc index b2459a7c..31843283 100644 --- a/examples/nesemu1.cc +++ b/examples/nesemu1.cc @@ -47,6 +47,8 @@ #include "third_party/getopt/getopt.h" #include "tool/viz/lib/knobs.h" +STATIC_YOINK("zip_uri_support"); + #define USAGE \ " [ROM] [FMV]\n\ \n\ @@ -1818,12 +1820,13 @@ size_t FindZipGames(void) { for (i = 0, cf = ZIP_CDIR_OFFSET(zipos->cdir); i < ZIP_CDIR_RECORDS(zipos->cdir); ++i, cf += ZIP_CFILE_HDRSIZE(zipos->map + cf)) { - if ((name = strndup(ZIP_CFILE_NAME(zipos->map + cf), - ZIP_CFILE_NAMESIZE(zipos->map + cf))) && - endswith(name, ".nes")) { + if (ZIP_CFILE_NAMESIZE(zipos->map + cf) > 4 && + !memcmp((ZIP_CFILE_NAME(zipos->map + cf) + + ZIP_CFILE_NAMESIZE(zipos->map + cf) - 4), + ".nes", 4) && + (name = xasprintf("zip:%.*s", ZIP_CFILE_NAMESIZE(zipos->map + cf), + ZIP_CFILE_NAME(zipos->map + cf)))) { APPEND(&zipgames_.p, &zipgames_.i, &zipgames_.n, &name); - } else { - free(name); } } } @@ -1842,7 +1845,7 @@ int SelectGameFromZip(void) { rc = 0; if ((line = GetLine())) { i = MAX(0, MIN(zipgames_.i - 1, atoi(line))); - uri = xasprintf("zip:%s", zipgames_.p[i]); + uri = zipgames_.p[i]; rc = PlayGame(uri, NULL); free(uri); } else {