1
0
mirror of https://frontier.innolan.net/rainlance/amiga-tz.git synced 2026-05-03 12:37:01 +00:00
Files
amiga-tz/library/time_time.c
2015-07-25 23:35:51 +02:00

119 lines
2.7 KiB
C

//--------------------------------------------------------------------------//
// This file is in the public domain, so clarified as of //
// 2009-05-17 by Arthur David Olson. //
//--------------------------------------------------------------------------//
#include "compiler.h"
#include "lib_macros.h"
#include "time_proto.h"
// -------------------------------------------------------------------------- //
// 2922 is the number of days between 1.1.1970 and 1.1.1978
// (2 leap years and 6 normal)
// 2922 * 24 * 60 * 60 = 252460800
// -------------------------------------------------------------------------- //
#define AMIGAOFFSET 252460800
/**
*
* @brief
* The time () function returns the value of time in seconds since 0 hours,
* 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time. If an
* error occurs, time () returns 0.
*
* The return value is also stored in * tloc , provided that tloc is non-null.
*
*/
#include "compiler.h"
#include "lib_macros.h"
#include "time_proto.h"
#include <dos/var.h>
#include <devices/timer.h>
#include <libraries/locale.h>
time_t ASM time(
REG(a0, time_t *tloc)
)
{
struct timeval tv;
time_t time;
GetSysTime(&tv);
time = (time_t)(tv.tv_secs + AMIGAOFFSET);
time = time - gmtoffset(time);
if (tloc) {
*tloc = time;
}
return time;
}
int ASM gmtoffset(
REG(d0, time_t locale_time)
)
{
struct tm tm;
time_t time = locale_time;
localtime_rz(lclptr, &time, &tm);
mktime(&tm);
return tm.tm_gmtoff;
}
void ASM getsystime(
REG(a0, struct timeval *tv)
)
{
GetSysTime(tv);
}
void ASM setsystime(
REG(a0, struct timeval *tv)
)
{
TimeRequest->tr_node.io_Command = TR_SETSYSTIME;
TimeRequest->tr_time.tv_secs = (long)tv->tv_secs;
TimeRequest->tr_time.tv_micro = tv->tv_micro;
DoIO((struct IORequest*)TimeRequest);
}
int ASM gettimeofday(
REG(a0, struct timeval *tv),
REG(a1, const timezone_t tz)
)
{
struct tm tm;
time_t time;
TimeRequest->tr_node.io_Command = TR_GETSYSTIME;
DoIO((struct IORequest*)TimeRequest);
tv->tv_secs = (long)TimeRequest->tr_time.tv_secs + AMIGAOFFSET;
tv->tv_micro = TimeRequest->tr_time.tv_micro;
time = tv->tv_secs;
if (tz) {
gmtime_r(&time, &tm);
tv->tv_secs = mktime_z(tz, &tm);
}
return 0;
}
int ASM settimeofday(
REG(a0, const struct timeval *tv),
REG(a1, const timezone_t tz)
)
{
// TODO: Include timezone in logic
TimeRequest->tr_node.io_Command = TR_SETSYSTIME;
TimeRequest->tr_time.tv_secs = (long)tv->tv_secs - AMIGAOFFSET;
TimeRequest->tr_time.tv_micro = tv->tv_micro;
DoIO((struct IORequest*)TimeRequest);
return 0;
}