POSIX conversions

Milt Ratcliff milt at mem.pe-nelson.com
Tue Jun 11 09:15:24 AEST 1991


I am trying to make several programs POSIX compliant.  As part of the effort I
am confronted with a need to convert routines which measure time.

To provide formatted time strings, the strftime function is relatively easy to
use.  To provide the input to the strftime function, gettimeofday has been
used and the seconds part of the timeval struct(tv_sec) passed to localtime.
This, in turn, has provided the tm struct used by strftime.

The use of gettimeofday has served a dual purpose, the first described above.
In addition it provides a very high resolution timer capatility, returning
the elapsed time in u-seconds since Jan. 1, 1970.  Obviously, the resolution
is actually controlled by the hardware clock, but it will provide resolution
within that restraint.  

My question concerns a replacement for the gettimeofday function which will
provide this level of timing resolution within a POSIX routine.  The POSIX
documents I am reading imply the use of either clock() or times().  My
intention is to use times() which is required by POSIX while clock() is
required by Standard C but not POSIX.  Also, I am not sure of the meaning of
'Standard C'(I am using "POSIX Programmer's Guide by Donald Lewine, O'Reilly &
Associates, Inc.).  Is this the correct approach and can I expect the results
to be equivalent to the data obtained from gettimeofday?

Thanks,


Milt
Milt Ratcliff
milt at pe-nelson.com
PE-Nelson
Cupertino, CA



More information about the Comp.std.c mailing list