timex.h

Utility library for comparing and computing timestamps.

US_PER_SEC

The number of microseconds per second.

1
(1000000U)
SEC_PER_MIN

The number of seconds per minute.

1
(60U)
CS_PER_SEC

The number of centiseconds per second.

1
(100U)
MS_PER_SEC

The number of milliseconds per second.

1
(1000U)
US_PER_MS

The number of microseconds per millisecond.

1
(1000U)
NS_PER_US

The number of nanoseconds per microsecond.

1
(1000U)
TIMEX_MAX_STR_LEN

The maximum length of the string representation of a timex timestamp.

1
(20)
timex_t timex_add(const timex_t a, const timex_t b)

Adds two timestamps.

Parameters

a:First summand
b:Second summand

Return values

  • The sum of the two timestamps
timex_t timex_sub(const timex_t a, const timex_t b)

Subtracts two timestamps.

Parameters

a:The minuend
b:The subtrahend

Return values

  • The difference a - b
timex_t timex_set(uint32_t seconds, uint32_t microseconds)

Initializes a timex timestamp.

Parameters

seconds:Number of seconds to set
microseconds:Number of microseconds to set

Return values

  • The initialized timex timestamp
int timex_cmp(const timex_t a, const timex_t b)

Compares two timex timestamps.

Parameters

a:The first timestamp to compare to
b:The second timestamp to compare with

Return values

  • -1 when a is smaller
  • 0 if equal
  • 1 if a is bigger
void timex_normalize(timex_t * time)

Corrects timex structure so that microseconds < 1000000.

Parameters

time:Pointer to the timestamp to normalize

int timex_isnormalized(const timex_t * time)

Tests a timex timestamp for normalization.

Parameters

time:Pointer to the timestamp to check

Return values

  • true for a normalized timex_t
  • false otherwise
uint64_t timex_uint64(const timex_t a)

Converts a timex timestamp to a 64 bit value.

Parameters

a:The timestamp to convert

Return values

  • timex representation as uint64_t
timex_t timex_from_uint64(const uint64_t timestamp)

Converts a 64 bit value of microseconds to a timex timestamp.

Parameters

timestamp:The timestamp to convert.

Return values

  • a timex representation of an uint64 timestamp.
const char * timex_to_str(timex_t t, char * timestamp)

Converts a timex timestamp to a string.

Parameters

t:The timestamp to convert
timestamp:The output char buffer for the converted timestamp

Note

The timestamp will be normalized

Return values

  • A pointer to the string representation of the timestamp
struct timex_t

A timex timestamp.

Note

If a timestamp is not normalized, the number of microseconds might be > 1000000

uint32_t seconds

number of seconds

uint32_t microseconds

number of microseconds