Skip to content

Instantly share code, notes, and snippets.

@rw-r-r-0644
Last active February 28, 2019 20:01
Show Gist options
  • Save rw-r-r-0644/614fba631b3e7f01d4d98f1e0e17d5ab to your computer and use it in GitHub Desktop.
Save rw-r-r-0644/614fba631b3e7f01d4d98f1e0e17d5ab to your computer and use it in GitHub Desktop.
RE of some coreinit functions
#include <wut.h>
/* 32 bit unix time_t */
typedef uint32_t time32_t;
/* coreinit: convert COS time to POSIX time */
time32_t __OSCalendarTimeToPOSIXTime(OSCalendarTime *td)
{
/* compute number of days to epoch */
uint32_t epoch_days = (1970 * 365) + GetLeapDays(1970);
/* compute number of days to this year */
uint32_t days = (td->tm_year * 365) + GetLeapDays(td->tm_year);
days += GetYearDays(td->tm_year, td->tm_mon);
days += td->tm_mday - 1;
/* compute posix time */
time32_t unix_time = (days - epoch_days) * 86400;
unix_time += td->tm_hour * 3600;
unix_time += td->tm_min * 60;
unix_time += td->tm_sec;
return unix_time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment