From 5ade5bb0ea4c6579a62d063193bd552b678e9064 Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Sun, 18 Jun 2006 08:16:55 +0000 Subject: [PATCH] * include/sys/time.h: Add header guard. Add extern "C" bracketing for __cplusplus. (gettimeofday): Add prototype. * mingwex/gettimeofday.c: New file. * mingwex/makefile.in: Add gettimeofday source and object. --- winsup/mingw/ChangeLog | 8 +++++ winsup/mingw/include/sys/time.h | 24 +++++++++++++- winsup/mingw/mingwex/Makefile.in | 5 +-- winsup/mingw/mingwex/gettimeofday.c | 49 +++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100755 winsup/mingw/mingwex/gettimeofday.c diff --git a/winsup/mingw/ChangeLog b/winsup/mingw/ChangeLog index 35c5ddebb..a813425ec 100644 --- a/winsup/mingw/ChangeLog +++ b/winsup/mingw/ChangeLog @@ -1,3 +1,11 @@ +2006-06-18 Danny Smith + + * include/sys/time.h: Add header guard. Add extern "C" bracketing + for __cplusplus. + (gettimeofday): Add prototype. + * mingwex/gettimeofday.c: New file. + * mingwex/makefile.in: Add gettimeofday source and object. + 2006-06-13 Danny Smith * include/math.h (HUGE_VAL): Define as builtin if __GNUC__ >= 3.3, diff --git a/winsup/mingw/include/sys/time.h b/winsup/mingw/include/sys/time.h index bcd550945..f3dcc3646 100644 --- a/winsup/mingw/include/sys/time.h +++ b/winsup/mingw/include/sys/time.h @@ -1,6 +1,11 @@ - +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ #include +#ifdef __cplusplus +extern "C" { +#endif + #ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ #define _TIMEVAL_DEFINED struct timeval { @@ -14,3 +19,20 @@ struct timeval { ((tvp)->tv_usec cmp (uvp)->tv_usec)) #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 #endif /* _TIMEVAL_DEFINED */ + +/* + Implementation as per: + The Open Group Base Specifications, Issue 6 + IEEE Std 1003.1, 2004 Edition + + The timezone pointer arg is ignored. Errors are ignored. +*/ +int __cdecl gettimeofday(struct timeval *__restrict__, + void *__restrict__ /* tzp (unused) */); + +#ifdef __cplusplus +} +#endif + + +#endif /* _SYS_TIME_H_ */ diff --git a/winsup/mingw/mingwex/Makefile.in b/winsup/mingw/mingwex/Makefile.in index feb9bd670..651169d75 100644 --- a/winsup/mingw/mingwex/Makefile.in +++ b/winsup/mingw/mingwex/Makefile.in @@ -35,7 +35,8 @@ DISTFILES = Makefile.in configure configure.in \ testwmem.c tst-aligned-malloc.c ulltoa.c ulltow.c wcstof.c \ wcstoimax.c wcstold.c wcstoumax.c wctrans.c wctype.c \ wdirent.c wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c wtoll.c \ - wcrtomb.c wctob.c mbrtowc.c btowc.c mb_wc_common.h + wcrtomb.c wctob.c mbrtowc.c btowc.c mb_wc_common.h \ + gettimeofday.c MATH_DISTFILES = \ acosf.c acosl.c asinf.c asinl.c atan2f.c atan2l.c \ atanf.c atanl.c cbrt.c cbrtf.c cbrtl.c ceilf.S ceill.S \ @@ -163,7 +164,7 @@ FENV_OBJS = fesetround.o fegetround.o \ feclearexcept.o feholdexcept.o fegetexceptflag.o \ feraiseexcept.o fetestexcept.o fesetexceptflag.o POSIX_OBJS = \ - dirent.o wdirent.o getopt.o ftruncate.o + dirent.o wdirent.o getopt.o ftruncate.o gettimeofday.o REPLACE_OBJS = \ mingw-aligned-malloc.o mingw-fseek.o COMPLEX_OBJS = \ diff --git a/winsup/mingw/mingwex/gettimeofday.c b/winsup/mingw/mingwex/gettimeofday.c new file mode 100755 index 000000000..194cf0499 --- /dev/null +++ b/winsup/mingw/mingwex/gettimeofday.c @@ -0,0 +1,49 @@ +/* + * gettimeofday + * Implementation according to: + * The Open Group Base Specifications Issue 6 + * IEEE Std 1003.1, 2004 Edition + */ + +/* + * THIS SOFTWARE IS NOT COPYRIGHTED + * + * This source code is offered for use in the public domain. You may + * use, modify or distribute it freely. + * + * This code is distributed in the hope that it will be useful but + * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY + * DISCLAIMED. This includes but is not limited to warranties of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Contributed by: + * Danny Smith + */ + +#include +#define WIN32_LEAN_AND_MEAN +#include + +/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */ +#define _W32_FT_OFFSET (116444736000000000ULL) + + +int __cdecl gettimeofday(struct timeval *__restrict__ tp, + void *__restrict__ tzp __attribute__((unused))) + { + union { + unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */ + FILETIME ft; + } _now; + + if(tp) + { + GetSystemTimeAsFileTime (&_now.ft); + tp->tv_usec=(long)((_now.ns100 / 10ULL) % 1000000ULL ); + tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000ULL); + } + /* Always return 0 as per Open Group Base Specifications Issue 6. + Do not set errno on error. */ + return 0; +} +