BeOS: Porting UNIX Applications

Chapter 19: Time Support

Overview

Time on most computers is handled by some simple variables and structures, and these have been built upon using a number of functions to produce what we call time under UNIX and now POSIX. The BeOS supports the basic POSIX types, with some additional UNIX functions thrown in for good measure.

19.1 Standard Variables and Defines

The epoch is the point at which time began. As far as UNIX and most other operating systems are concerned, this is January 1, 1970, otherwise known as the epoch. The value is the basic unit of time and is stored as a long, which has been typed

   #include    typedef long time_t;

Using a 32-bit integer should make the counter last about 68 years, because it is a signed integer value (2 31). This allows the timer to specify a time up to January 18, 2038, based on the epoch more than long enough to last most people!

The difficulty with time_t is that the figure is calculated in seconds, when it is often useful to be able to count in milliseconds. The timeval structure is used to describe the same basic figure as that described using time_t, but the granularity has been reduced to milliseconds:

   #include    struct timeval {     long tv_sec;     long tv_usec;   }
Table 19-1: Time types and value range

Type

Member

Range

Description

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Pulse Generators
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.