mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Improve zipos path handling (#579)
This change adds opendir, readdir, and stat support for the /zip/ root, as well as directories not explicitly encoded in the zip file.
This commit is contained in:
parent
494d74271b
commit
1ef955c33b
5 changed files with 73 additions and 10 deletions
|
@ -326,6 +326,7 @@ static struct dirent *readdir_impl(DIR *dir) {
|
|||
uint8_t *s, *p;
|
||||
struct Zipos *zip;
|
||||
struct dirent *ent;
|
||||
struct dirent *lastent;
|
||||
struct dirent_bsd *bsd;
|
||||
struct dirent_netbsd *nbsd;
|
||||
struct dirent_openbsd *obsd;
|
||||
|
@ -351,6 +352,20 @@ static struct dirent *readdir_impl(DIR *dir) {
|
|||
ent->d_type = S_ISDIR(mode) ? DT_DIR : DT_REG;
|
||||
memcpy(ent->d_name, s, ent->d_reclen);
|
||||
ent->d_name[ent->d_reclen] = 0;
|
||||
} else {
|
||||
lastent = (struct dirent *)dir->buf;
|
||||
n = p - s;
|
||||
n = MIN(n, 255);
|
||||
if (!lastent->d_ino || (n != lastent->d_reclen) ||
|
||||
memcmp(lastent->d_name, s, n)) {
|
||||
ent = lastent;
|
||||
ent->d_ino++;
|
||||
ent->d_off = -1;
|
||||
ent->d_reclen = n;
|
||||
ent->d_type = DT_DIR;
|
||||
memcpy(ent->d_name, s, ent->d_reclen);
|
||||
ent->d_name[ent->d_reclen] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
dir->zip.offset += ZIP_CFILE_HDRSIZE(zip->map + dir->zip.offset);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue