2020-06-15 14:18:57 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
2023-12-08 03:11:56 +00:00
|
|
|
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
2020-06-15 14:18:57 +00:00
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
2020-06-15 14:18:57 +00:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2023-08-19 13:41:06 +00:00
|
|
|
#include "libc/calls/internal.h"
|
2022-06-09 03:01:28 +00:00
|
|
|
#include "libc/calls/struct/stat.h"
|
2023-08-19 13:41:06 +00:00
|
|
|
#include "libc/intrin/atomic.h"
|
2022-09-04 05:50:23 +00:00
|
|
|
#include "libc/intrin/safemacros.internal.h"
|
2023-08-16 01:24:53 +00:00
|
|
|
#include "libc/runtime/zipos.internal.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/str/str.h"
|
2022-09-04 05:50:23 +00:00
|
|
|
#include "libc/sysv/consts/s.h"
|
2023-06-10 01:02:06 +00:00
|
|
|
#include "libc/zip.internal.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2023-10-03 21:40:03 +00:00
|
|
|
int __zipos_stat_impl(struct Zipos *zipos, size_t cf, struct stat *st) {
|
|
|
|
size_t lf;
|
2023-08-16 14:54:40 +00:00
|
|
|
bzero(st, sizeof(*st));
|
|
|
|
st->st_nlink = 1;
|
|
|
|
st->st_dev = zipos->dev;
|
|
|
|
st->st_blksize = FRAMESIZE;
|
|
|
|
if (cf == ZIPOS_SYNTHETIC_DIRECTORY) {
|
2023-08-19 13:41:06 +00:00
|
|
|
st->st_mode = S_IFDIR | (0555 & ~atomic_load_explicit(
|
|
|
|
&__umask, memory_order_acquire));
|
2020-06-15 14:18:57 +00:00
|
|
|
} else {
|
2023-10-03 21:40:03 +00:00
|
|
|
lf = GetZipCfileOffset(zipos->map + cf);
|
|
|
|
st->st_mode = GetZipCfileMode(zipos->map + cf);
|
|
|
|
st->st_size = GetZipLfileUncompressedSize(zipos->map + lf);
|
2023-08-16 14:54:40 +00:00
|
|
|
st->st_blocks =
|
2023-10-03 21:40:03 +00:00
|
|
|
roundup(GetZipLfileCompressedSize(zipos->map + lf), 512) / 512;
|
|
|
|
GetZipCfileTimestamps(zipos->map + cf, &st->st_mtim, &st->st_atim,
|
2023-08-16 14:54:40 +00:00
|
|
|
&st->st_ctim, 0);
|
|
|
|
st->st_birthtim = st->st_ctim;
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|
2023-08-16 14:54:40 +00:00
|
|
|
return 0;
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|