XMMS2
timestamp.c
Go to the documentation of this file.
1 #include <math.h>
2 
4 
5 /* helper functions to convert timestamps */
6 
7 double
8 tv2ts (struct timeval *t)
9 {
10  return t->tv_sec + t->tv_usec / 1000000.0;
11 }
12 
13 double
14 net2ts (int32_t* s)
15 {
16  return (int32_t)(ntohl (s[0])) + (int32_t)(ntohl (s[1])) / 1000000.0;
17 }
18 
19 void
20 ts2net (int32_t* d, double t)
21 {
22  double s, u;
23  u = modf (t, &s);
24  d[0] = htonl ((int32_t)s);
25  d[1] = htonl ((int32_t)(u * 1000000.0));
26 }
27 
28 void
29 tv2net (int32_t* d, struct timeval *t)
30 {
31  d[0] = htonl ((int32_t)t->tv_sec);
32  d[1] = htonl ((int32_t)t->tv_usec);
33 }
void ts2net(int32_t *d, double t)
Definition: timestamp.c:20
double net2ts(int32_t *s)
Definition: timestamp.c:14
void tv2net(int32_t *d, struct timeval *t)
Definition: timestamp.c:29
double tv2ts(struct timeval *t)
Definition: timestamp.c:8