mirror of
https://github.com/devkitPro/wut.git
synced 2026-09-30 05:54:29 -05:00
wutdevoptab: simplify the __wut_fs_translate_time implementation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "devoptab_fs.h"
|
||||
#include "../wutnewlib/wut_clock.h"
|
||||
|
||||
char *
|
||||
__wut_fs_fixpath(struct _reent *r,
|
||||
@@ -50,20 +51,8 @@ mode_t __wut_fs_translate_mode(FSStat fileStat) {
|
||||
return retMode | ownerFlags | groupFlags | userFlags;
|
||||
}
|
||||
|
||||
|
||||
time_t __wut_fs_translate_time(FSTime timeValue) {
|
||||
OSCalendarTime fileTime;
|
||||
FSTimeToCalendarTime(timeValue, &fileTime);
|
||||
struct tm posixTime = {0};
|
||||
posixTime.tm_year = fileTime.tm_year - 1900;
|
||||
posixTime.tm_mon = fileTime.tm_mon;
|
||||
posixTime.tm_mday = fileTime.tm_mday;
|
||||
posixTime.tm_hour = fileTime.tm_hour;
|
||||
posixTime.tm_min = fileTime.tm_min;
|
||||
posixTime.tm_sec = fileTime.tm_sec;
|
||||
posixTime.tm_yday = fileTime.tm_yday;
|
||||
posixTime.tm_wday = fileTime.tm_wday;
|
||||
return mktime(&posixTime);
|
||||
return (timeValue /1000000) + EPOCH_DIFF_SECS(WIIU_FSTIME_EPOCH_YEAR);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -21,7 +21,7 @@ __wut_clock_gettime(clockid_t clock_id,
|
||||
time -= OSSecondsToTicks(tp->tv_sec);
|
||||
tp->tv_nsec = (long)OSTicksToNanoseconds(time);
|
||||
|
||||
tp->tv_sec += EPOCH_DIFF_SECS;
|
||||
tp->tv_sec += EPOCH_DIFF_SECS(WIIU_OSTIME_EPOCH_YEAR);
|
||||
} else {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// The Wii U epoch is at 2000, so we must map it to 1970 for gettime
|
||||
#define WIIU_EPOCH_YEAR (2000)
|
||||
// The Wii U OSTime epoch is at 2000, so we must map it to 1970 for gettime
|
||||
#define WIIU_OSTIME_EPOCH_YEAR (2000)
|
||||
// The Wii U FSTime epoch is at 1980, so we must map it to 1970 for gettime
|
||||
#define WIIU_FSTIME_EPOCH_YEAR (1980)
|
||||
|
||||
#define EPOCH_YEAR (1970)
|
||||
#define EPOCH_YEARS_SINCE_LEAP 2
|
||||
#define EPOCH_YEARS_SINCE_CENTURY 70
|
||||
#define EPOCH_YEARS_SINCE_LEAP_CENTURY 370
|
||||
|
||||
#define EPOCH_DIFF_YEARS (2000 - EPOCH_YEAR)
|
||||
#define EPOCH_DIFF_DAYS \
|
||||
((EPOCH_DIFF_YEARS * 365) + \
|
||||
(EPOCH_DIFF_YEARS - 1 + EPOCH_YEARS_SINCE_LEAP) / 4 - \
|
||||
(EPOCH_DIFF_YEARS - 1 + EPOCH_YEARS_SINCE_CENTURY) / 100 + \
|
||||
(EPOCH_DIFF_YEARS - 1 + EPOCH_YEARS_SINCE_LEAP_CENTURY) / 400)
|
||||
#define EPOCH_DIFF_SECS (60ull * 60ull * 24ull * (uint64_t)EPOCH_DIFF_DAYS)
|
||||
#define EPOCH_DIFF_YEARS(year) (year - EPOCH_YEAR)
|
||||
#define EPOCH_DIFF_DAYS(year) \
|
||||
((EPOCH_DIFF_YEARS(year) * 365) + \
|
||||
(EPOCH_DIFF_YEARS(year) - 1 + EPOCH_YEARS_SINCE_LEAP) / 4 - \
|
||||
(EPOCH_DIFF_YEARS(year) - 1 + EPOCH_YEARS_SINCE_CENTURY) / 100 + \
|
||||
(EPOCH_DIFF_YEARS(year) - 1 + EPOCH_YEARS_SINCE_LEAP_CENTURY) / 400)
|
||||
#define EPOCH_DIFF_SECS(year) (60ull * 60ull * 24ull * (uint64_t)EPOCH_DIFF_DAYS(year))
|
||||
|
||||
@@ -16,7 +16,7 @@ __wut_gettod_r(struct _reent *ptr,
|
||||
time -= OSSecondsToTicks(tp->tv_sec);
|
||||
tp->tv_usec = (long)OSTicksToMicroseconds(time);
|
||||
|
||||
tp->tv_sec += EPOCH_DIFF_SECS;
|
||||
tp->tv_sec += EPOCH_DIFF_SECS(WIIU_OSTIME_EPOCH_YEAR);
|
||||
}
|
||||
|
||||
if (tz != NULL) {
|
||||
|
||||
Reference in New Issue
Block a user