More consolidation of timezone code:
* 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
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#ifndef _SYS_TIME_H
|
||||
#define _SYS_TIME_H
|
||||
/*
|
||||
/*
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
|
||||
@@ -40,7 +40,7 @@ extern "C" {
|
||||
|
||||
extern int getitimer(int which, struct itimerval *value);
|
||||
extern int setitimer(int which, const struct itimerval *value, struct itimerval *oldValue);
|
||||
extern int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
extern int gettimeofday(struct timeval *tv, void *tz);
|
||||
|
||||
extern int utimes(const char *name, const struct timeval times[2]);
|
||||
/* legacy */
|
||||
|
||||
@@ -15,14 +15,6 @@
|
||||
|
||||
#define RTC_EPOCH_BASE_YEAR 1970
|
||||
|
||||
typedef struct rtc_info {
|
||||
uint32 time;
|
||||
bool is_gmt;
|
||||
int32 tz_minuteswest;
|
||||
bool tz_dsttime;
|
||||
} rtc_info;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -31,8 +23,6 @@ status_t rtc_init(kernel_args *args);
|
||||
bigtime_t rtc_boot_time(void);
|
||||
// Returns the time at which the system was booted in microseconds since Jan 1, 1970 UTC.
|
||||
|
||||
status_t get_rtc_info(rtc_info *info);
|
||||
|
||||
// Both functions use the passed struct tm only partially
|
||||
// (no tm_wday, tm_yday, tm_isdst).
|
||||
uint32 rtc_tm_to_secs(const struct tm *t);
|
||||
@@ -40,8 +30,8 @@ void rtc_secs_to_tm(uint32 seconds, struct tm *t);
|
||||
|
||||
bigtime_t _user_system_time(void);
|
||||
status_t _user_set_real_time_clock(uint32 time);
|
||||
status_t _user_set_timezone(int32 timezoneOffset, bool daylightSavingTime);
|
||||
status_t _user_get_timezone(int32 *_timezoneOffset, bool *_daylightSavingTime);
|
||||
status_t _user_set_timezone(int32 timezoneOffset);
|
||||
status_t _user_get_timezone(int32 *_timezoneOffset);
|
||||
status_t _user_set_real_time_clock_is_gmt(bool isGMT);
|
||||
status_t _user_get_real_time_clock_is_gmt(bool *_isGMT);
|
||||
|
||||
|
||||
@@ -363,10 +363,8 @@ extern status_t _kern_stop_watching(dev_t device, ino_t node, port_id port,
|
||||
|
||||
// time functions
|
||||
extern status_t _kern_set_real_time_clock(uint32 time);
|
||||
extern status_t _kern_set_timezone(int32 timezoneOffset,
|
||||
bool daylightSavingTime);
|
||||
extern status_t _kern_get_timezone(int32 *_timezoneOffset,
|
||||
bool *_daylightSavingTime);
|
||||
extern status_t _kern_set_timezone(int32 timezoneOffset);
|
||||
extern status_t _kern_get_timezone(int32 *_timezoneOffset);
|
||||
extern status_t _kern_set_real_time_clock_is_gmt(bool isGMT);
|
||||
extern status_t _kern_get_real_time_clock_is_gmt(bool *_isGMT);
|
||||
|
||||
|
||||
@@ -69,16 +69,22 @@ dump_directory(uint8 *buffer)
|
||||
static void
|
||||
get_tzoffset()
|
||||
{
|
||||
rtc_info info;
|
||||
|
||||
if (tzoffset != -1)
|
||||
return;
|
||||
|
||||
if (get_rtc_info(&info) < 0) {
|
||||
dprintf("error getting rtc info\n");
|
||||
} else {
|
||||
tzoffset = info.tz_minuteswest;
|
||||
}
|
||||
// tzoffset used to be set to a bogus value (timezone offset in seconds),
|
||||
// we could try to use something like the following ...
|
||||
//
|
||||
// int32 tzOffsetInSeconds;
|
||||
// if (_kern_get_timezone(&tzOffsetInSeconds) < 0) {
|
||||
// dprintf("error getting timezone offset\n");
|
||||
// } else {
|
||||
// tzoffset = tzOffsetInSeconds / 60;
|
||||
// }
|
||||
//
|
||||
// but I'd rather like to spare us the specific kernel call,
|
||||
// so we hardcode the timezone (let's see if it makes any difference)
|
||||
tzoffset = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ setTimeZoneOffset(BPath path)
|
||||
return;
|
||||
}
|
||||
|
||||
_kern_set_timezone(timeZoneOffset, false);
|
||||
_kern_set_timezone(timeZoneOffset);
|
||||
printf("timezone offset is %ld seconds from GMT.\n", timeZoneOffset);
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ TimeZoneView::_SetSystemTimeZone()
|
||||
|
||||
mutable_locale_roster->SetDefaultTimeZone(timeZone);
|
||||
|
||||
_kern_set_timezone(timeZone.OffsetFromGMT(), false);
|
||||
_kern_set_timezone(timeZone.OffsetFromGMT());
|
||||
|
||||
fSetZone->SetEnabled(false);
|
||||
fLastUpdateMinute = -1;
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
static struct real_time_data *sRealTimeData;
|
||||
static bool sIsGMT = false;
|
||||
static bigtime_t sTimezoneOffset = 0;
|
||||
static bool sDaylightSavingTime = false;
|
||||
|
||||
|
||||
/*! Write the system time to CMOS. */
|
||||
@@ -129,21 +128,6 @@ real_time_clock_usecs(void)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
get_rtc_info(rtc_info *info)
|
||||
{
|
||||
if (info == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
info->time = real_time_clock();
|
||||
info->is_gmt = sIsGMT;
|
||||
info->tz_minuteswest = sTimezoneOffset / 1000000LL;
|
||||
info->tz_dsttime = sDaylightSavingTime;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
@@ -202,22 +186,6 @@ rtc_secs_to_tm(uint32 seconds, struct tm *t)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
/*! This is called from the gettimeofday() implementation that's part of the
|
||||
kernel.
|
||||
*/
|
||||
status_t
|
||||
_kern_get_timezone(time_t *_timezoneOffset, bool *_daylightSavingTime)
|
||||
{
|
||||
*_timezoneOffset = (time_t)(sTimezoneOffset / 1000000LL);
|
||||
*_daylightSavingTime = sDaylightSavingTime;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - syscalls
|
||||
|
||||
|
||||
@@ -242,7 +210,7 @@ _user_set_real_time_clock(uint32 time)
|
||||
|
||||
|
||||
status_t
|
||||
_user_set_timezone(time_t timezoneOffset, bool daylightSavingTime)
|
||||
_user_set_timezone(time_t timezoneOffset)
|
||||
{
|
||||
bigtime_t offset = (bigtime_t)timezoneOffset * 1000000LL;
|
||||
|
||||
@@ -263,7 +231,6 @@ _user_set_timezone(time_t timezoneOffset, bool daylightSavingTime)
|
||||
}
|
||||
|
||||
sTimezoneOffset = offset;
|
||||
sDaylightSavingTime = daylightSavingTime;
|
||||
|
||||
TRACE(("new system_time_offset %Ld\n",
|
||||
arch_rtc_get_system_time_offset(sRealTimeData)));
|
||||
@@ -273,15 +240,12 @@ _user_set_timezone(time_t timezoneOffset, bool daylightSavingTime)
|
||||
|
||||
|
||||
status_t
|
||||
_user_get_timezone(time_t *_timezoneOffset, bool *_daylightSavingTime)
|
||||
_user_get_timezone(time_t *_timezoneOffset)
|
||||
{
|
||||
time_t offset = (time_t)(sTimezoneOffset / 1000000LL);
|
||||
|
||||
if (!IS_USER_ADDRESS(_timezoneOffset)
|
||||
|| !IS_USER_ADDRESS(_daylightSavingTime)
|
||||
|| user_memcpy(_timezoneOffset, &offset, sizeof(time_t)) < B_OK
|
||||
|| user_memcpy(_daylightSavingTime, &sDaylightSavingTime,
|
||||
sizeof(bool)) < B_OK)
|
||||
|| user_memcpy(_timezoneOffset, &offset, sizeof(time_t)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
return B_OK;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
int
|
||||
gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
gettimeofday(struct timeval *tv, void *tz)
|
||||
{
|
||||
if (tv != NULL) {
|
||||
bigtime_t usecs = real_time_clock_usecs();
|
||||
@@ -18,14 +18,8 @@ gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
tv->tv_usec = usecs % 1000000;
|
||||
}
|
||||
|
||||
if (tz != NULL) {
|
||||
time_t timezoneOffset;
|
||||
bool daylightSavingTime;
|
||||
_kern_get_timezone(&timezoneOffset, &daylightSavingTime);
|
||||
|
||||
tz->tz_minuteswest = timezoneOffset;
|
||||
tz->tz_dsttime = daylightSavingTime;
|
||||
}
|
||||
// struct timezone (tz) has been deprecated since long and its exact
|
||||
// semantics are a bit unclear, so we need not bother to deal with it
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user