]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
client: drop unnecessary function
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 30 Sep 2020 14:30:36 +0000 (16:30 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 1 Oct 2020 10:58:17 +0000 (12:58 +0200)
Replace cvt_to_sec_usec() with a UTI_DoubleToTimespec() call.

client.c

index 7d596573c8f95eb2c99e9646fd22b51685747617..ec5f354ecf5624deab855ec3e6ef45bc1696682d 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1001,36 +1001,17 @@ process_cmd_dfreq(CMD_Request *msg, char *line)
 
 /* ================================================== */
 
-static void
-cvt_to_sec_usec(double x, long *sec, long *usec) {
-  long s, us;
-  s = (long) x;
-  us = (long)(0.5 + 1.0e6 * (x - (double) s));
-  while (us >= 1000000) {
-    us -= 1000000;
-    s += 1;
-  }
-  while (us < 0) {
-    us += 1000000;
-    s -= 1;
-  }
-  
-  *sec = s;
-  *usec = us;
-}
-
-/* ================================================== */
-
 static void
 process_cmd_doffset(CMD_Request *msg, char *line)
 {
+  struct timeval tv;
   double doffset;
-  long sec, usec;
+
   msg->command = htons(REQ_DOFFSET);
   if (sscanf(line, "%lf", &doffset) == 1) {
-    cvt_to_sec_usec(doffset, &sec, &usec);
-    msg->data.doffset.sec = htonl(sec);
-    msg->data.doffset.usec = htonl(usec);
+    UTI_DoubleToTimeval(doffset, &tv);
+    msg->data.doffset.sec = htonl(tv.tv_sec);
+    msg->data.doffset.usec = htonl(tv.tv_usec);
   } else {
     msg->data.doffset.sec = htonl(0);
     msg->data.doffset.usec = htonl(0);