diff --git a/libmaxsi/include/time.h b/libmaxsi/include/time.h index f4741166..99c4b59d 100644 --- a/libmaxsi/include/time.h +++ b/libmaxsi/include/time.h @@ -1,6 +1,6 @@ /****************************************************************************** - COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012. This file is part of LibMaxsi. @@ -20,7 +20,7 @@ time.h Time declarations. -******************************************************************************/ +*******************************************************************************/ #ifndef _TIME_H #define _TIME_H 1 @@ -32,6 +32,18 @@ __BEGIN_DECLS @include(clock_t.h) @include(time_t.h) +struct tm +{ + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_isdst; +}; + clock_t clock(void); time_t time(time_t* t); char* ctime(const time_t* timep); diff --git a/libmaxsi/time.cpp b/libmaxsi/time.cpp index 868a1cbf..fdbaa5ed 100644 --- a/libmaxsi/time.cpp +++ b/libmaxsi/time.cpp @@ -1,6 +1,6 @@ /****************************************************************************** - COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012. This file is part of LibMaxsi. @@ -20,7 +20,7 @@ time.cpp Useful time functions. -******************************************************************************/ +*******************************************************************************/ #include #include @@ -49,18 +49,22 @@ namespace Maxsi extern "C" int gettimeofday(struct timeval* tp, void* /*tzp*/) { - tp->tv_sec = 0; - tp->tv_usec = 0; + uintmax_t sinceboot; + uptime(&sinceboot); + tp->tv_sec = sinceboot / 1000000ULL; + tp->tv_usec = sinceboot % 1000000ULL; return 0; } extern "C" time_t time(time_t* t) { - *t = 0; - return 0; + struct timeval tv; + gettimeofday(&tv, NULL); + time_t result = tv.tv_sec; + return t ? *t = result : result; } - extern "C" char* ctime(const time_t* timep) + extern "C" char* ctime(const time_t* /*timep*/) { return (char*) "ctime(3) is not implemented"; }