From 0759c6e503daf989d69a8698d9c4d37387036aca Mon Sep 17 00:00:00 2001 From: resver Date: Sat, 4 Feb 2012 08:02:08 +0000 Subject: [PATCH] Use a more portable way to obtain timezone offset. git-svn-id: http://exfat.googlecode.com/svn/trunk@254 60bc1c72-a15a-11de-b98f-4500b42dc123 --- libexfat/exfat.h | 1 + libexfat/mount.c | 3 +-- libexfat/time.c | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libexfat/exfat.h b/libexfat/exfat.h index 6727e6a..c30963c 100644 --- a/libexfat/exfat.h +++ b/libexfat/exfat.h @@ -189,5 +189,6 @@ void exfat_unmount(struct exfat* ef); time_t exfat_exfat2unix(le16_t date, le16_t time, uint8_t centisec); void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time, uint8_t* centisec); +void exfat_tzset(void); #endif /* ifndef EXFAT_H_INCLUDED */ diff --git a/libexfat/mount.c b/libexfat/mount.c index db4bc7b..9eaa849 100644 --- a/libexfat/mount.c +++ b/libexfat/mount.c @@ -24,7 +24,6 @@ #include #include #include -#include static uint64_t rootdir_size(const struct exfat* ef) { @@ -143,7 +142,7 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options) { int rc; - tzset(); + exfat_tzset(); memset(ef, 0, sizeof(struct exfat)); parse_options(ef, options); diff --git a/libexfat/time.c b/libexfat/time.c index e91ec48..7170449 100644 --- a/libexfat/time.c +++ b/libexfat/time.c @@ -20,6 +20,10 @@ #include "exfat.h" +/* timezone offset from UTC in seconds; positive for western timezones, + negative for eastern ones */ +static long exfat_timezone; + #define SEC_IN_MIN 60ll #define SEC_IN_HOUR (60 * SEC_IN_MIN) #define SEC_IN_DAY (24 * SEC_IN_HOUR) @@ -94,7 +98,7 @@ time_t exfat_exfat2unix(le16_t date, le16_t time, uint8_t centisec) unix_time += centisec / 100; /* exFAT stores timestamps in local time, so we correct it to UTC */ - unix_time += timezone; + unix_time += exfat_timezone; return unix_time; } @@ -102,7 +106,7 @@ time_t exfat_exfat2unix(le16_t date, le16_t time, uint8_t centisec) void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time, uint8_t* centisec) { - time_t shift = EPOCH_DIFF_SEC + timezone; + time_t shift = EPOCH_DIFF_SEC + exfat_timezone; uint16_t day, month, year; uint16_t twosec, min, hour; int days; @@ -141,3 +145,12 @@ void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time, if (centisec) *centisec = (unix_time % 2) * 100; } + +void exfat_tzset(void) +{ + time_t now; + + tzset(); + now = time(NULL); + exfat_timezone = mktime(gmtime(&now)) - now; +} -- 2.11.0