From 622e0176e31a2819a21393eacc18cc85a0e78186 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 29 May 2012 00:27:06 +0200 Subject: [PATCH] Added stubs for gmtime(3), localtime(3) and utime(3). --- libmaxsi/include/time.h | 13 +++++++++++++ libmaxsi/time.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libmaxsi/include/time.h b/libmaxsi/include/time.h index 99c4b59d..0b47ef80 100644 --- a/libmaxsi/include/time.h +++ b/libmaxsi/include/time.h @@ -44,9 +44,22 @@ struct tm int tm_isdst; }; +struct utimbuf +{ + time_t actime; + time_t modtime; +}; + clock_t clock(void); time_t time(time_t* t); char* ctime(const time_t* timep); +struct tm* localtime_r(const time_t* timer, struct tm* ret); +struct tm* gmtime_r(const time_t* timer, struct tm* ret); +#if !defined(_SORTIX_SOURCE) +struct tm* localtime(const time_t* timer); +struct tm* gmtime(const time_t* timer); +#endif +int utime(const char* filepath, const struct utimbuf* times); __END_DECLS diff --git a/libmaxsi/time.cpp b/libmaxsi/time.cpp index fdbaa5ed..dbc098ba 100644 --- a/libmaxsi/time.cpp +++ b/libmaxsi/time.cpp @@ -64,9 +64,50 @@ namespace Maxsi return t ? *t = result : result; } + extern "C" struct tm* localtime_r(const time_t* timer, struct tm* ret) + { + time_t time = *timer; + ret->tm_sec = time % 60; // No leap seconds. + ret->tm_min = (time / 60) % 60; + ret->tm_hour = (time / 60 / 60) % 24; + ret->tm_mday = 0; + ret->tm_mon = 0; + ret->tm_year = 0; + ret->tm_wday = 0; + ret->tm_isdst = 0; + return ret; + } + + extern "C" struct tm* gmtime_r(const time_t* timer, struct tm* ret) + { + return localtime_r(timer, ret); + } + + // TODO: Who the hell designed the below two functions? I vote that + // these be removed from Sortix soon - although that'd require fixing + // a lot of applications.. + + extern "C" struct tm* localtime(const time_t* timer) + { + static struct tm hack_localtime_ret; + return localtime_r(timer, &hack_localtime_ret); + } + + extern "C" struct tm* gmtime(const time_t* timer) + { + static struct tm hack_gmtime_ret; + return gmtime_r(timer, &hack_gmtime_ret); + } + extern "C" char* ctime(const time_t* /*timep*/) { return (char*) "ctime(3) is not implemented"; } + + extern "C" int utime(const char* filepath, const struct utimbuf* times) + { + // TODO: Sure, I did that! There is no kernel support for this yet. + return 0; + } } }