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 */
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
-#include <time.h>
static uint64_t rootdir_size(const struct exfat* ef)
{
{
int rc;
- tzset();
+ exfat_tzset();
memset(ef, 0, sizeof(struct exfat));
parse_options(ef, options);
#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)
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;
}
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;
if (centisec)
*centisec = (unix_time % 2) * 100;
}
+
+void exfat_tzset(void)
+{
+ time_t now;
+
+ tzset();
+ now = time(NULL);
+ exfat_timezone = mktime(gmtime(&now)) - now;
+}