* gettimeofday() now also fills in a passed in struct timezone, if any,

using the new _kern_get_timezone() syscall.
* Added an implementation of ftime() based on the above function, this
  may fix bug #308.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16786 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-03-14 14:36:46 +00:00
parent f46bdd1c9a
commit 821d63fe0a
3 changed files with 48 additions and 12 deletions

View File

@ -4,6 +4,7 @@ UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ;
MergeObject posix_sys.o :
chmod.c
ftime.c
getrusage.c
gettimeofday.c
itimer.c

View File

@ -0,0 +1,29 @@
/*
* Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <sys/time.h>
#include <sys/timeb.h>
int
ftime(struct timeb *timeb)
{
struct timezone tz;
struct timeval tv;
if (timeb == NULL)
return -1;
gettimeofday(&tv, &tz);
timeb->time = tv.tv_sec;
timeb->millitm = tv.tv_usec / 1000UL;
timeb->timezone = tz.tz_minuteswest;
timeb->dstflag = tz.tz_dsttime;
return 0;
}

View File

@ -1,25 +1,31 @@
/*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
/*
* Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <sys/time.h>
#include <OS.h>
#include <syscalls.h>
int
int
gettimeofday(struct timeval *tv, struct timezone *tz)
{
bigtime_t usecs;
if (tv != NULL) {
bigtime_t usecs = real_time_clock_usecs();
if (tv == NULL)
return 0;
tv->tv_sec = usecs / 1000000;
tv->tv_usec = usecs % 1000000;
}
usecs = real_time_clock_usecs();
if (tz != NULL) {
time_t timezoneOffset;
bool daylightSavingTime;
_kern_get_timezone(&timezoneOffset, &daylightSavingTime);
tv->tv_sec = usecs / 1000000;
tv->tv_usec = usecs % 1000000;
tz->tz_minuteswest = timezoneOffset;
tz->tz_dsttime = daylightSavingTime;
}
return 0;
}