Merge "reference-ril/atchannel.c: Fix time conversion" am: 0bbaed7
am: 230df4a
* commit '230df4ab9c69358026634079c1dece849b10d2f0':
reference-ril/atchannel.c: Fix time conversion
Change-Id: I02f358e240858166c4360b368b23c0dfdee67ff1
diff --git a/reference-ril/atchannel.c b/reference-ril/atchannel.c
index f38545d..ac01cbc 100644
--- a/reference-ril/atchannel.c
+++ b/reference-ril/atchannel.c
@@ -86,6 +86,7 @@
static int writeline (const char *s);
#ifndef USE_NP
+#define NS_PER_S 1000000000
static void setTimespecRelative(struct timespec *p_ts, long long msec)
{
struct timeval tv;
@@ -97,6 +98,11 @@
a relative time again */
p_ts->tv_sec = tv.tv_sec + (msec / 1000);
p_ts->tv_nsec = (tv.tv_usec + (msec % 1000) * 1000L ) * 1000L;
+ /* assuming tv.tv_usec < 10^6 */
+ if (p_ts->tv_nsec >= NS_PER_S) {
+ p_ts->tv_sec++;
+ p_ts->tv_nsec -= NS_PER_S;
+ }
}
#endif /*USE_NP*/