2020-06-15 14:18:57 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ 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
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2021-03-01 07:42:35 +00:00
|
|
|
#include "libc/bits/safemacros.internal.h"
|
2022-06-09 03:01:28 +00:00
|
|
|
#include "libc/calls/struct/stat.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/str/str.h"
|
2020-08-25 11:23:25 +00:00
|
|
|
#include "libc/sysv/errfuns.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/zip.h"
|
2020-11-28 20:01:51 +00:00
|
|
|
#include "libc/zipos/zipos.internal.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2020-08-25 11:23:25 +00:00
|
|
|
int __zipos_stat_impl(struct Zipos *zipos, size_t cf, struct stat *st) {
|
2021-04-18 18:34:59 +00:00
|
|
|
size_t lf;
|
2020-08-25 11:23:25 +00:00
|
|
|
if (zipos && st) {
|
2021-09-28 05:58:51 +00:00
|
|
|
bzero(st, sizeof(*st));
|
2021-04-18 18:34:59 +00:00
|
|
|
lf = GetZipCfileOffset(zipos->map + cf);
|
2022-03-21 14:34:19 +00:00
|
|
|
st->st_mode = GetZipCfileMode(zipos->map + cf);
|
2021-04-18 18:34:59 +00:00
|
|
|
st->st_size = GetZipLfileUncompressedSize(zipos->map + lf);
|
2020-08-25 11:23:25 +00:00
|
|
|
st->st_blocks =
|
2021-04-18 18:34:59 +00:00
|
|
|
roundup(GetZipLfileCompressedSize(zipos->map + lf), 512) / 512;
|
2021-08-14 13:17:56 +00:00
|
|
|
GetZipCfileTimestamps(zipos->map + cf, &st->st_mtim, &st->st_atim,
|
|
|
|
&st->st_ctim, 0);
|
2021-09-04 05:19:41 +00:00
|
|
|
st->st_birthtim = st->st_ctim;
|
2020-08-25 11:23:25 +00:00
|
|
|
return 0;
|
2020-06-15 14:18:57 +00:00
|
|
|
} else {
|
2020-08-25 11:23:25 +00:00
|
|
|
return einval();
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|
|
|
|
}
|