How [non]standard is gettimeofday?

F

Fred Ma

Hello,

I was trying to make sure that my code is
not dysfunctionally dependent on quirks
particular to my current system. I read
the comp.lang.c faq on subsecond timing.
It says there's no standard way, but suggests
looking at gettimeofday (which I currently
use on solaris, but got worried when I
found documentation on it missing from
cygwin). From previous posts on gettimeofday,
it *seems* it is defacto standard in the unix
community. I wonder if anyone can offer their
opinion of how prevelant it is. I can live
with defacto standards in the unix community.
And since it's available on cygwin, that
makes it accessible to me on a PC. Thanks
for any feedback.

Fred
 
M

Maurizio Loreti

For this kind of subjects, you want to refer to a specific standard;
namely ISO/IEC and IEEE Std 1003.1-2003, the current POSIX standard.
Most of the Unix systems around here and several API available under
different environment are POSIX compliant; and a copy of the standard
may be bought for a nominal fee.

WRT gettimeofday, ISO/IEC 1003.1-2003 says:

NAME
gettimeofday - get the date and time

SYNOPSIS
#include <sys/time.h>
int gettimeofday(struct timeval *restrict tp,
void *restrict tzp);

In turn, the struct timeval is composed by a time_t and a suseconds_t,
defined as "arithmetic types that can define times in seconds" and
"... in microseconds", respectively.

What POSIX says, in short, is that every implementation is free to used a
different arithmetic type for time_t's; signed or unsigned integers,
32 or 64 bit integers, also doubles could be theoretically used.

As long as you use POSIX types like time_t, and POSIX interfaces like
difftime(3) or ctime(3), your programs are conforming, and portable
between different implementations.

For your particular implementation (Solaris) consult your manuals to
know how actually time_t and friends are implemented over there.
 
A

Alan Balmer

Hello,

I was trying to make sure that my code is
not dysfunctionally dependent on quirks
particular to my current system. I read
the comp.lang.c faq on subsecond timing.
It says there's no standard way, but suggests
looking at gettimeofday (which I currently
use on solaris, but got worried when I
found documentation on it missing from
cygwin). From previous posts on gettimeofday,
it *seems* it is defacto standard in the unix
community. I wonder if anyone can offer their
opinion of how prevelant it is. I can live
with defacto standards in the unix community.
And since it's available on cygwin, that
makes it accessible to me on a PC. Thanks
for any feedback.

Fred

According to Gallmeister, it's provided under Berkeley and SVR4
systems. POSIX.4 standardizes several functions which you'd like, but
it's not universal, and I'm pretty sure Cygwin doesn't support them.
You can check with

#ifdef _POSIX_TIMERS
 
A

Anonymous

the comp.lang.c faq on subsecond timing.
It says there's no standard way, but suggests
looking at gettimeofday

this is a POSIX function. Hence it will exist on any platform that
complies to the posix standard. Other platforms eg MSDOS, Windwos,
have no obligation to support it.

My recommendation would be to isolate this function in your own
wrapper. There is undoubtedly a Windows function to do the same thing,
if you read the documentation.
 
D

David Schwartz

My recommendation would be to isolate this function in your own
wrapper. There is undoubtedly a Windows function to do the same thing,
if you read the documentation.

There's _ftime, _ftime64, GetSystemTime, GetLocalTime,
GetSystemTimeAsFileTime. Unfortunately, Windows keeps its system time in
local time.

DS
 
F

Fred Ma

Floyd said:
Others have answered your specific question, but I thought you'd
also like to have this url,

http://www.unix.org/single_unix_specification/

Web access to the POSIX Standard.

Thanks, all. I actually visited that website
before, long ago. It just seems like there are
many names for standards (for unix and libc's)
out there, so it was helpful to even know that
looking at the posix standard would good enough
to cover many unixes.

As for cygwin, it is a posix emulation layer, so
it does provide a gettimeofday function. It just
isn't in its info database, at least no more than
as an item in a list. Admittedly, there's much
more I can do to become familiar with how to get
the info database more complete, but I have to
pace myself on time spent doing that (else out
be out of the game in the thesis research I'm
suppose to be doing).

Thank you all again.

Fred
 
G

Geoff Clare

this is a POSIX function.
True.

Hence it will exist on any platform that
complies to the posix standard.

Not true. It's an *optional* POSIX function (part of the XSI option),
so not all POSIX systems have to provide it. However, UNIX systems are
required to implement the XSI option, so all UNIX systems do provide it.
 
M

Mark McIntyre

hey, whats with this? All of a sudden my dratted newsfeed supplier is
anonymising me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,104
Messages
2,570,643
Members
47,247
Latest member
youngcoin

Latest Threads

Top