From 821d63fe0ac176bda60e59a7a867d8159c030a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 14 Mar 2006 14:36:46 +0000 Subject: [PATCH] * 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 --- src/system/libroot/posix/sys/Jamfile | 1 + src/system/libroot/posix/sys/ftime.c | 29 ++++++++++++++++++++ src/system/libroot/posix/sys/gettimeofday.c | 30 ++++++++++++--------- 3 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 src/system/libroot/posix/sys/ftime.c diff --git a/src/system/libroot/posix/sys/Jamfile b/src/system/libroot/posix/sys/Jamfile index b92d59129b..0f9f0a1afb 100644 --- a/src/system/libroot/posix/sys/Jamfile +++ b/src/system/libroot/posix/sys/Jamfile @@ -4,6 +4,7 @@ UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ; MergeObject posix_sys.o : chmod.c + ftime.c getrusage.c gettimeofday.c itimer.c diff --git a/src/system/libroot/posix/sys/ftime.c b/src/system/libroot/posix/sys/ftime.c new file mode 100644 index 0000000000..6834ecf433 --- /dev/null +++ b/src/system/libroot/posix/sys/ftime.c @@ -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 +#include + + +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; +} + diff --git a/src/system/libroot/posix/sys/gettimeofday.c b/src/system/libroot/posix/sys/gettimeofday.c index 7e863abe6d..f234d10984 100644 --- a/src/system/libroot/posix/sys/gettimeofday.c +++ b/src/system/libroot/posix/sys/gettimeofday.c @@ -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 -#include +#include -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; }