OSDN Git Service

Use a more portable way to obtain timezone offset.
authorresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sat, 4 Feb 2012 08:02:08 +0000 (08:02 +0000)
committerresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sat, 4 Feb 2012 08:02:08 +0000 (08:02 +0000)
git-svn-id: http://exfat.googlecode.com/svn/trunk@254 60bc1c72-a15a-11de-b98f-4500b42dc123

libexfat/exfat.h
libexfat/mount.c
libexfat/time.c

index 6727e6a..c30963c 100644 (file)
@@ -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 */
index db4bc7b..9eaa849 100644 (file)
@@ -24,7 +24,6 @@
 #include <errno.h>
 #include <unistd.h>
 #include <sys/types.h>
-#include <time.h>
 
 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);
index e91ec48..7170449 100644 (file)
 
 #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;
+}