7e965f506d
* dropped DaylightSavingTime from real_time_clock code in kernel, it was never really being used for what it meant (and just being referred to by gettimeofday(), which put a different meaning to it * adjusted the syscalls get_timezone() & set_timezone() as well as their callers accordingly * got rid of get_rtc_info() and rtc_info struct in kernel, as it was only being referred to by the FAT add-on and that one (like gettimeofday()) put a different meaning to tz_minuteswest. Added a comment to FAT's util.c showing a possible solution, should the hardcoded GMT timezone pose a problem. * fixed declaration of gettimeofday() to match POSIX base specs, issue 7 * changed implementation of gettimeofday() to not bother trying to fill struct timezone - it was using wrong values before, anyway. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37888 a95241bf-73f2-0310-859d-f6bbb57e9c96
93 lines
1.9 KiB
C++
93 lines
1.9 KiB
C++
/*
|
|
* Copyright 2004, Jérôme Duval, jerome.duval@free.fr.
|
|
* Copyright 2010, Oliver Tappe <zooey@hirschkaefer.de>
|
|
* All rights reserved. Distributed under the terms of the MIT License.
|
|
*/
|
|
|
|
|
|
#include <File.h>
|
|
#include <FindDirectory.h>
|
|
#include <Message.h>
|
|
#include <OS.h>
|
|
#include <Path.h>
|
|
|
|
#include <syscalls.h>
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
|
|
static char* program;
|
|
|
|
|
|
void
|
|
setRealTimeClockIsGMT(BPath path)
|
|
{
|
|
path.Append("RTC_time_settings");
|
|
BFile file;
|
|
status_t status = file.SetTo(path.Path(), B_READ_ONLY);
|
|
if (status != B_OK) {
|
|
fprintf(stderr, "%s: can't open RTC settings file\n", program);
|
|
return;
|
|
}
|
|
|
|
char buffer[10];
|
|
ssize_t bytesRead = file.Read(buffer, sizeof(buffer));
|
|
if (bytesRead < 0) {
|
|
fprintf(stderr, "%s: unable to read RTC settings file\n", program);
|
|
return;
|
|
}
|
|
bool isGMT = strncmp(buffer, "local", 5) != 0;
|
|
|
|
_kern_set_real_time_clock_is_gmt(isGMT);
|
|
printf("RTC stores %s time.\n", isGMT ? "GMT" : "local" );
|
|
}
|
|
|
|
|
|
void
|
|
setTimeZoneOffset(BPath path)
|
|
{
|
|
path.Append("Time settings");
|
|
BFile file;
|
|
status_t status = file.SetTo(path.Path(), B_READ_ONLY);
|
|
if (status != B_OK) {
|
|
fprintf(stderr, "%s: can't open Time settings file\n", program);
|
|
return;
|
|
}
|
|
|
|
BMessage settings;
|
|
status = settings.Unflatten(&file);
|
|
if (status != B_OK) {
|
|
fprintf(stderr, "%s: unable to parse Time settings file\n", program);
|
|
return;
|
|
}
|
|
int32 timeZoneOffset;
|
|
if (settings.FindInt32("offset", &timeZoneOffset) != B_OK) {
|
|
fprintf(stderr, "%s: no timezone offset found\n", program);
|
|
return;
|
|
}
|
|
|
|
_kern_set_timezone(timeZoneOffset);
|
|
printf("timezone offset is %ld seconds from GMT.\n", timeZoneOffset);
|
|
}
|
|
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
program = argv[0];
|
|
|
|
BPath path;
|
|
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
|
if (status != B_OK) {
|
|
fprintf(stderr, "%s: can't find settings directory\n", program);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
setRealTimeClockIsGMT(path);
|
|
setTimeZoneOffset(path);
|
|
|
|
return 0;
|
|
}
|