gettimeofday

gettimeofday

Post by Gilad Benjamin » Fri, 10 Feb 1995 17:01:17



I am porting code from SunOS 4.1 to Solaris 2.3
In my original code I use both ftime() and gettimeofday().

While porting, I discovered that in Solaris 2, ftime is part of
the BSD compatability library, which the SUN people recommend not to use.

In Sun's porting guide the replacement for ftime is gettimeofday.

I then discovered some weird things about gettimeofday:

1. It gets 2 parameters in AIX & SunOS, and 1 in Solaris 2.3
2. It's prototype is non-existent in header files (Solaris & AIX)
3. It's not covered in Stevens' UNIX programming book, which usually
   answers all my UNIX programming questions.

I can still use it, but the whole thing seems very fishy (as is my
spelling).

 
 
 

gettimeofday

Post by Stephen Hinch » Tue, 14 Feb 1995 17:31:43


: I am porting code from SunOS 4.1 to Solaris 2.3
: In my original code I use both ftime() and gettimeofday().

: While porting, I discovered that in Solaris 2, ftime is part of
: the BSD compatability library, which the SUN people recommend not to use.

: In Sun's porting guide the replacement for ftime is gettimeofday.

That's funny, if you do a man on gettimeofday on Solaris 2.4 it says this
function is part of the SunOS/BSD Compatibility Library.

: I then discovered some weird things about gettimeofday:

: 1. It gets 2 parameters in AIX & SunOS, and 1 in Solaris 2.3

In Solaris 2.4 gettimeofday gets 2 parameters, struct timeval & struct
timezone.

: 2. It's prototype is non-existent in header files (Solaris & AIX)
: 3. It's not covered in Stevens' UNIX programming book, which usually
:    answers all my UNIX programming questions.

: I can still use it, but the whole thing seems very fishy (as is my
: spelling).

 
 
 

gettimeofday

Post by Kaleb KEITHL » Wed, 15 Feb 1995 00:07:50




>>That's funny, if you do a man on gettimeofday on Solaris 2.4 it says this
>>function is part of the SunOS/BSD Compatibility Library.
>Manual pages are known to be wrong.

'man -s 3b gettimeofday' has the SunOS/BSD compatibility function and
'man -s 3c gettimeofday' has the SVR4 function. The former takes two
arguments, the latter, one; but...

Quote:>>In Solaris 2.4 gettimeofday gets 2 parameters, struct timeval & struct
>>timezone.
>No.  It really only gets one.  The prototype for C++ is wrong.
>Anyway, gettimeofday never uses the timezone parameter (which
>is a broken BSD-ism).  

...SVR4 is going to reverse itself and revert to the two argument version
of gettimeofday for API and ABI compatibility. This is already evident in
Unixware 2.0 and if I'm not mistaken will eventually be the case in Solaris.

Quote:>So if you rely on anything being put there, don't.

Good advice in any event.

--

Kaleb KEITHLEY

 
 
 

gettimeofday

Post by Guy Harr » Wed, 15 Feb 1995 10:00:45



>...SVR4 is going to reverse itself and revert to the two argument version
>of gettimeofday for API and ABI compatibility.

...at least to the extent of permitting a *NULL* pointer to "struct
timezone" to be used as the second argument.  The impression I had from
what somebody at Sun said was that they would *NOT*, however, bother
filling in a "struct timezone" if you pass a non-NULL pointer.

That's as it should be - even programs written for modern BSD systems
shouldn't be passing in anything other than a NULL pointer.  If they
have to convert between local time and UNIX time, they should use
"localtime()" or "mktime()" to do that.  (BTW, SunOS 4.1[.x] *did* have
"mktime()", even though I forgot to update the 4.1[.x] man page when I
put the "mktime()" from the Arthur Olson code into 4.1.)