2006-07-26 17:19:52 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de.
|
2004-11-18 06:08:36 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-10-05 21:07:03 +04:00
|
|
|
|
|
|
|
|
2006-07-26 17:19:52 +04:00
|
|
|
#include <libroot_private.h>
|
|
|
|
#include <real_time_data.h>
|
|
|
|
#include <syscalls.h>
|
|
|
|
|
2006-05-13 19:52:32 +04:00
|
|
|
#include <FindDirectory.h>
|
2002-10-05 21:07:03 +04:00
|
|
|
#include <OS.h>
|
2004-11-18 06:08:36 +03:00
|
|
|
|
2006-05-13 19:52:32 +04:00
|
|
|
#include <stdio.h>
|
2004-11-07 04:19:27 +03:00
|
|
|
#include <string.h>
|
2004-11-18 06:08:36 +03:00
|
|
|
#include <syslog.h>
|
|
|
|
|
2002-10-05 21:07:03 +04:00
|
|
|
|
2006-01-04 05:17:59 +03:00
|
|
|
static struct real_time_data sRealTimeDefaults;
|
2004-11-18 06:08:36 +03:00
|
|
|
static struct real_time_data *sRealTimeData;
|
2004-11-06 20:34:39 +03:00
|
|
|
|
2004-11-18 06:08:36 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
__init_time(void)
|
2004-11-06 20:34:39 +03:00
|
|
|
{
|
2006-01-04 05:17:59 +03:00
|
|
|
bool setDefaults = false;
|
2004-11-10 01:45:48 +03:00
|
|
|
area_id dataArea;
|
2004-11-07 04:19:27 +03:00
|
|
|
area_info info;
|
2004-11-10 01:45:48 +03:00
|
|
|
|
|
|
|
dataArea = find_area("real time data userland");
|
2004-11-18 06:08:36 +03:00
|
|
|
if (dataArea < 0 || get_area_info(dataArea, &info) < B_OK) {
|
|
|
|
syslog(LOG_ERR, "error finding real time data area: %s\n", strerror(dataArea));
|
|
|
|
sRealTimeData = &sRealTimeDefaults;
|
2006-01-04 05:17:59 +03:00
|
|
|
setDefaults = true;
|
2004-11-18 06:08:36 +03:00
|
|
|
} else
|
|
|
|
sRealTimeData = (struct real_time_data *)info.address;
|
|
|
|
|
2006-01-04 05:17:59 +03:00
|
|
|
__arch_init_time(sRealTimeData, setDefaults);
|
2004-11-06 20:34:39 +03:00
|
|
|
}
|
|
|
|
|
2002-10-05 21:07:03 +04:00
|
|
|
|
|
|
|
uint32
|
|
|
|
real_time_clock(void)
|
|
|
|
{
|
2006-01-04 05:17:59 +03:00
|
|
|
return (__arch_get_system_time_offset(sRealTimeData) + system_time())
|
|
|
|
/ 1000000;
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-18 06:08:36 +03:00
|
|
|
bigtime_t
|
|
|
|
real_time_clock_usecs(void)
|
2002-10-05 21:07:03 +04:00
|
|
|
{
|
2006-01-04 05:17:59 +03:00
|
|
|
return __arch_get_system_time_offset(sRealTimeData) + system_time();
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-18 06:08:36 +03:00
|
|
|
void
|
|
|
|
set_real_time_clock(uint32 secs)
|
2002-10-05 21:07:03 +04:00
|
|
|
{
|
2004-11-18 06:08:36 +03:00
|
|
|
_kern_set_real_time_clock(secs);
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
set_timezone(char *timezone)
|
|
|
|
{
|
2006-05-13 19:52:32 +04:00
|
|
|
char path[B_PATH_NAME_LENGTH];
|
|
|
|
char tzfilename[B_PATH_NAME_LENGTH];
|
|
|
|
bool isGMT;
|
|
|
|
|
2004-11-22 03:35:22 +03:00
|
|
|
status_t err;
|
|
|
|
struct tm *tm;
|
|
|
|
time_t t;
|
2006-05-13 19:52:32 +04:00
|
|
|
|
|
|
|
if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, -1, true, path, B_PATH_NAME_LENGTH)) != B_OK) {
|
|
|
|
fprintf(stderr, "can't find settings directory: %s\n", strerror(err));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
strcat(path, "/timezone");
|
|
|
|
|
|
|
|
err = unlink(path);
|
|
|
|
if (err != B_OK) {
|
|
|
|
fprintf(stderr, "can't unlink: %s\n", strerror(err));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
err = symlink(timezone, path);
|
|
|
|
if (err != B_OK) {
|
|
|
|
fprintf(stderr, "can't symlink: %s\n", strerror(err));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
_kern_get_tzfilename(tzfilename, sizeof(tzfilename), &isGMT);
|
|
|
|
_kern_set_tzfilename(timezone, strlen(timezone), isGMT);
|
|
|
|
tzset();
|
2004-11-22 03:35:22 +03:00
|
|
|
|
|
|
|
time(&t);
|
|
|
|
tm = localtime(&t);
|
|
|
|
|
2004-11-26 18:04:16 +03:00
|
|
|
if ((err = _kern_set_timezone(tm->tm_gmtoff, tm->tm_isdst)) < B_OK)
|
2004-11-22 03:35:22 +03:00
|
|
|
return err;
|
|
|
|
|
|
|
|
return B_OK;
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bigtime_t
|
2006-07-26 17:19:52 +04:00
|
|
|
set_alarm(bigtime_t when, uint32 mode)
|
2002-10-05 21:07:03 +04:00
|
|
|
{
|
2006-07-26 17:19:52 +04:00
|
|
|
return _kern_set_alarm(when, mode);
|
2002-10-05 21:07:03 +04:00
|
|
|
}
|