Converts a relative binary timestamp to two timespec structures that express relative time and inaccuracy. Format #include <utc.h> int utc_binreltime(*timesp, *inaccsp, *utc) reltimespec_t *timesp; timespec_t *inaccsp; const utc_t *utc;
1 – Parameters
Input utc Relative binary timestamp. Output timesp Time component of the relative binary timestamp, in the form of seconds and nanoseconds since the base time (1970-01- 01:00:00:00.0 + 00:00I0). inaccsp Inaccuracy component of the relative binary timestamp, in the form of seconds and nanoseconds.
2 – Description
The Binary Relative Time routine converts a relative binary timestamp to two timespec structures that express relative time and inaccuracy. These timespec structures describe a time interval.
3 – Returns
0 Indicates that the routine executed successfully. -1 Indicates an invalid time argument or invalid results.
4 – Example
The following example measures the duration of a process, then prints the resulting relative time and inaccuracy. utc_t before, duration; reltimespec_t tduration; timespec_t iduration; /* * Get the time before the start of the operation... */ utc_gettime(&before); /* Out: Before binary timestamp */ /* * ...Later... * * Subtract, getting the duration as a relative time. * * NOTE: The NULL argument is used to obtain the current time. */ utc_subtime(&duration, /* Out: Duration rel bin timestamp */ (utc_t *)0, /* In: After binary timestamp */ &before); /* In: Before binary timestamp */ /* * Convert the relative times to timespec structures... */ utc_binreltime(&tduration, /* Out: Duration time timespec */ &iduration, /* Out: Duration inacc timespec */ &duration); /* In: Duration rel bin timestamp */ /* * Print the duration... */ printf("%d.%04d", tduration.tv_sec, (tduration.tv_nsec/10000)); if ((long)iduration.tv_sec == -1) printf("Iinf\n"); else printf("I%d.%04d\n", iduration.tv_sec, (iduration.tv_nsec/100000));
5 – Related Functions
utc_mkbinreltime