mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 15:38:22 +00:00
Introduce COSMOPOLITAN_DISABLE_ZIPOS environ var
This commit is contained in:
parent
8d1c81ac9f
commit
04bd488da7
2 changed files with 41 additions and 33 deletions
|
@ -65,6 +65,7 @@ static void __zipos_munmap_unneeded(const uint8_t *base, const uint8_t *cdir,
|
|||
*/
|
||||
struct Zipos *__zipos_get(void) {
|
||||
char *endptr;
|
||||
const char *s;
|
||||
struct stat st;
|
||||
static bool once;
|
||||
struct Zipos *res;
|
||||
|
@ -74,6 +75,7 @@ struct Zipos *__zipos_get(void) {
|
|||
static struct Zipos zipos;
|
||||
__zipos_lock();
|
||||
if (!once) {
|
||||
if (!(s = getenv("COSMOPOLITAN_DISABLE_ZIPOS"))) {
|
||||
// this environment variable may be a filename or file descriptor
|
||||
if ((progpath = getenv("COSMOPOLITAN_INIT_ZIPOS")) &&
|
||||
(x = strtol(progpath, &endptr, 10)) >= 0 && !*endptr) {
|
||||
|
@ -89,8 +91,9 @@ struct Zipos *__zipos_get(void) {
|
|||
fd = open(progpath, O_RDONLY);
|
||||
}
|
||||
if (fd != -1) {
|
||||
if (!fstat(fd, &st) && (map = mmap(0, st.st_size, PROT_READ,
|
||||
MAP_PRIVATE, fd, 0)) != MAP_FAILED) {
|
||||
if (!fstat(fd, &st) &&
|
||||
(map = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) !=
|
||||
MAP_FAILED) {
|
||||
if ((cdir = GetZipEocd(map, st.st_size, &err))) {
|
||||
__zipos_munmap_unneeded(map, cdir, map);
|
||||
zipos.map = map;
|
||||
|
@ -111,6 +114,10 @@ struct Zipos *__zipos_get(void) {
|
|||
} else {
|
||||
msg = -666;
|
||||
}
|
||||
} else {
|
||||
progpath = 0;
|
||||
msg = -777;
|
||||
}
|
||||
STRACE("__zipos_get(%#s) → %d% m", progpath, msg);
|
||||
once = true;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ ssize_t __zipos_parseuri(const char *uri, struct ZiposUri *out) {
|
|||
uri[2] == 'i' && //
|
||||
uri[3] == 'p' && //
|
||||
(!uri[4] || uri[4] == '/')) &&
|
||||
__zipos_get() &&
|
||||
(len = __zipos_normpath(out->path, uri + 4 + !!uri[4],
|
||||
sizeof(out->path))) < sizeof(out->path)) {
|
||||
return (out->len = len);
|
||||
|
|
Loading…
Add table
Reference in a new issue