client: drop unnecessary function

Replace cvt_to_sec_usec() with a UTI_DoubleToTimespec() call.
This commit is contained in:
Miroslav Lichvar 2020-09-30 16:30:36 +02:00
parent 944cf6e318
commit 642173e864

View file

@ -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);