Implement proper time zone support

Cosmopolitan now supports 104 time zones. They're embedded inside any
binary that links the localtime() function. Doing so adds about 100kb
to the binary size. This change also gets time zones working properly
on Windows for the first time. It's not needed to have /etc/localtime
exist on Windows, since we can get this information from WIN32. We're
also now updated to the latest version of Paul Eggert's TZ library.
This commit is contained in:
Justine Tunney 2024-05-04 23:05:36 -07:00
parent d5ebb1fa5b
commit b0df6c1fce
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
627 changed files with 3052 additions and 2077 deletions

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/fmt/libgen.h"
@ -36,8 +37,8 @@
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/time.h"
#include "libc/x/xasprintf.h"
#include "libc/x/xiso8601.h"
#include "libc/zip.internal.h"
#include "tool/decode/lib/asmcodegen.h"
#include "tool/decode/lib/disassemblehex.h"
@ -63,6 +64,24 @@ static __wur char *FormatDosTime(uint16_t dostime) {
(dostime >> 5) & 0b111111, (dostime << 1) & 0b111110);
}
char *xiso8601(struct timespec ts) {
struct tm tm;
if (!localtime_r(&ts.tv_sec, &tm))
return 0;
int len = 128;
char *res = malloc(len);
char *ptr = res;
char *end = res + len;
if (!res)
return 0;
ptr += strftime(ptr, end - ptr, "%Y-%m-%dT%H:%M:%S", &tm);
ptr += snprintf(ptr, end - ptr, "%09ld", ts.tv_nsec);
ptr += strftime(ptr, end - ptr, "%z", &tm);
unassert(ptr + 1 <= end);
unassert(realloc_in_place(res, ptr - end) == res);
return res;
}
void AdvancePosition(uint8_t *map, size_t *pos, size_t off) {
if (off > *pos) {
/* printf("\n/\t<%s>\n", "LIMBO"); */
@ -108,13 +127,13 @@ void ShowNtfs(uint8_t *ntfs, size_t n) {
"ntfs attribute tag value #1");
show(".short", gc(xasprintf("%hu", READ16LE(ntfs + 6))),
"ntfs attribute tag size");
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 8))),
gc(xasprintf("%s (%s)", "ntfs last modified time",
gc(xiso8601(&mtime)))));
show(
".quad", gc(xasprintf("%lu", READ64LE(ntfs + 8))),
gc(xasprintf("%s (%s)", "ntfs last modified time", gc(xiso8601(mtime)))));
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 16))),
gc(xasprintf("%s (%s)", "ntfs last access time", gc(xiso8601(&atime)))));
gc(xasprintf("%s (%s)", "ntfs last access time", gc(xiso8601(atime)))));
show(".quad", gc(xasprintf("%lu", READ64LE(ntfs + 24))),
gc(xasprintf("%s (%s)", "ntfs creation time", gc(xiso8601(&ctime)))));
gc(xasprintf("%s (%s)", "ntfs creation time", gc(xiso8601(ctime)))));
}
void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
@ -126,7 +145,7 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
if ((flag & 1) && n >= 4) {
show(".long", gc(xasprintf("%u", READ32LE(p))),
gc(xasprintf("%s (%s)", "last modified",
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
gc(xiso8601((struct timespec){READ32LE(p)})))));
p += 4;
n -= 4;
}
@ -135,7 +154,7 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
if ((flag & 1) && n >= 4) {
show(".long", gc(xasprintf("%u", READ32LE(p))),
gc(xasprintf("%s (%s)", "access time",
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
gc(xiso8601((struct timespec){READ32LE(p)})))));
p += 4;
n -= 4;
}
@ -143,7 +162,7 @@ void ShowExtendedTimestamp(uint8_t *p, size_t n, bool islocal) {
if ((flag & 1) && n >= 4) {
show(".long", gc(xasprintf("%u", READ32LE(p))),
gc(xasprintf("%s (%s)", "creation time",
gc(xiso8601(&(struct timespec){READ32LE(p)})))));
gc(xiso8601((struct timespec){READ32LE(p)})))));
p += 4;
n -= 4;
}