mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-28 13:30:29 +00:00
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:
parent
d5ebb1fa5b
commit
b0df6c1fce
627 changed files with 3052 additions and 2077 deletions
|
@ -45,7 +45,6 @@ TOOL_BUILD_DIRECTDEPS = \
|
|||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_THREAD \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_X \
|
||||
NET_HTTP \
|
||||
|
@ -57,6 +56,7 @@ TOOL_BUILD_DIRECTDEPS = \
|
|||
THIRD_PARTY_MUSL \
|
||||
THIRD_PARTY_REGEX \
|
||||
THIRD_PARTY_STB \
|
||||
THIRD_PARTY_TZ \
|
||||
THIRD_PARTY_XED \
|
||||
THIRD_PARTY_ZLIB \
|
||||
THIRD_PARTY_ZLIB_GZ \
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ TOOL_BUILD_LIB_A_DIRECTDEPS = \
|
|||
LIBC_SYSV_CALLS \
|
||||
LIBC_PROC \
|
||||
LIBC_THREAD \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_X \
|
||||
NET_HTTP \
|
||||
|
@ -54,7 +53,8 @@ TOOL_BUILD_LIB_A_DIRECTDEPS = \
|
|||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_MBEDTLS \
|
||||
THIRD_PARTY_XED \
|
||||
THIRD_PARTY_ZLIB
|
||||
THIRD_PARTY_ZLIB \
|
||||
THIRD_PARTY_TZ
|
||||
|
||||
TOOL_BUILD_LIB_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TOOL_BUILD_LIB_A_DIRECTDEPS),$($(x))))
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/nt/enum/fileflagandattributes.h"
|
||||
|
@ -31,7 +30,7 @@
|
|||
#include "libc/stdio/rand.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
#include "libc/zip.internal.h"
|
||||
|
|
|
@ -71,8 +71,7 @@
|
|||
#include "libc/temp.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/thread2.h"
|
||||
#include "libc/time/struct/tm.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/x/xsigaction.h"
|
||||
#include "net/http/escape.h"
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/zip.internal.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
|
|
|
@ -24,12 +24,12 @@ TOOL_CURL_DIRECTDEPS = \
|
|||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_TIME \
|
||||
NET_HTTP \
|
||||
NET_HTTPS \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_MBEDTLS \
|
||||
THIRD_PARTY_MUSL
|
||||
THIRD_PARTY_MUSL \
|
||||
THIRD_PARTY_TZ
|
||||
|
||||
TOOL_CURL_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TOOL_CURL_DIRECTDEPS),$($(x))))
|
||||
|
|
|
@ -33,11 +33,11 @@ TOOL_DECODE_DIRECTDEPS = \
|
|||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_X \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_TZ \
|
||||
THIRD_PARTY_XED \
|
||||
TOOL_DECODE_LIB
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -719,7 +719,7 @@
|
|||
(default-directory root)
|
||||
(compile-command (cosmo--compile-command this root nil mode "" "" ".runs")))
|
||||
(compile compile-command)
|
||||
(gdb (format "gdb -q -nh -i=mi %s -ex run" exec))))))
|
||||
(gdb (format "gdb -q -i=mi %s -ex run" exec))))))
|
||||
|
||||
(progn
|
||||
(define-key asm-mode-map (kbd "C-c C-d") 'cosmo-debug)
|
||||
|
|
|
@ -47,7 +47,6 @@ TOOL_NET_DIRECTDEPS = \
|
|||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME \
|
||||
LIBC_THREAD \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_X \
|
||||
|
@ -66,6 +65,7 @@ TOOL_NET_DIRECTDEPS = \
|
|||
THIRD_PARTY_MBEDTLS \
|
||||
THIRD_PARTY_REGEX \
|
||||
THIRD_PARTY_SQLITE3 \
|
||||
THIRD_PARTY_TZ \
|
||||
THIRD_PARTY_ZLIB \
|
||||
TOOL_ARGS \
|
||||
TOOL_BUILD_LIB \
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
#include "libc/sysv/consts/rusage.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "net/http/escape.h"
|
||||
#include "net/http/http.h"
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/time/clockstonanos.internal.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
#include "tool/build/lib/case.h"
|
||||
#include "tool/plinko/lib/char.h"
|
||||
|
@ -59,6 +58,13 @@ STATIC_STACK_SIZE(0x100000);
|
|||
#define DISPATCH(ea, tm, r, p1, p2) \
|
||||
GetDispatchFn(LO(ea))(ea, tm, r, p1, p2, GetShadow(LO(ea)))
|
||||
|
||||
static inline uint64_t ClocksToNanos(uint64_t x, uint64_t y) {
|
||||
// approximation of round(x*.323018) which is usually
|
||||
// the ratio between inva rdtsc ticks and nanoseconds
|
||||
uint128_t difference = x - y;
|
||||
return (difference * 338709) >> 20;
|
||||
}
|
||||
|
||||
static void Unwind(int S) {
|
||||
int s;
|
||||
dword t;
|
||||
|
|
|
@ -21,11 +21,17 @@
|
|||
#include "libc/nexgen32e/rdtsc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/clockstonanos.internal.h"
|
||||
#include "tool/plinko/lib/char.h"
|
||||
#include "tool/plinko/lib/plinko.h"
|
||||
#include "tool/plinko/lib/print.h"
|
||||
|
||||
static inline uint64_t ClocksToNanos(uint64_t x, uint64_t y) {
|
||||
// approximation of round(x*.323018) which is usually
|
||||
// the ratio between inva rdtsc ticks and nanoseconds
|
||||
uint128_t difference = x - y;
|
||||
return (difference * 338709) >> 20;
|
||||
}
|
||||
|
||||
static inline long GetVarInt(va_list va, signed char t) {
|
||||
if (t <= 0)
|
||||
return va_arg(va, int);
|
||||
|
|
|
@ -38,7 +38,6 @@ TOOL_VIZ_DIRECTDEPS = \
|
|||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_THREAD \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_VGA \
|
||||
LIBC_X \
|
||||
|
@ -50,6 +49,7 @@ TOOL_VIZ_DIRECTDEPS = \
|
|||
THIRD_PARTY_MAXMIND \
|
||||
THIRD_PARTY_MUSL \
|
||||
THIRD_PARTY_STB \
|
||||
THIRD_PARTY_TZ \
|
||||
THIRD_PARTY_XED \
|
||||
THIRD_PARTY_ZLIB \
|
||||
TOOL_DECODE_LIB \
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "libc/nexgen32e/x86info.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
#include "tool/decode/lib/idname.h"
|
||||
#include "tool/decode/lib/x86idnames.h"
|
||||
|
|
|
@ -38,12 +38,12 @@ TOOL_VIZ_LIB_A_DIRECTDEPS = \
|
|||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_X \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_DLMALLOC \
|
||||
THIRD_PARTY_GDTOA
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_TZ
|
||||
|
||||
TOOL_VIZ_LIB_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TOOL_VIZ_LIB_A_DIRECTDEPS),$($(x))))
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "tool/viz/lib/convolution.h"
|
||||
#include "tool/viz/lib/graphic.h"
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "tool/viz/lib/convolution.h"
|
||||
#include "tool/viz/lib/graphic.h"
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "tool/viz/lib/graphic.h"
|
||||
#include "tool/viz/lib/knobs.h"
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
#include "libc/sysv/consts/poll.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
|
||||
#define USAGE \
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/madv.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "tool/decode/lib/flagger.h"
|
||||
#include "tool/decode/lib/idname.h"
|
||||
#if defined(__x86_64__) && SupportsWindows()
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
#include "libc/sysv/consts/w.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/xsigaction.h"
|
||||
#include "third_party/getopt/getopt.internal.h"
|
||||
#include "third_party/stb/stb_image_resize.h"
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/time.h"
|
||||
#include "libc/x/xsigaction.h"
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue