* lib/boot-time-aux.h (get_linux_uptime): Compute struct timespec
using integer arithmetic rather than double.
* lib/boot-time.c, lib/readutmp.c: Don’t include c-strtod.h.
* modules/boot-time, modules/readutmp (Depends-on): Remove c-strtod.
2023-08-12 Paul Eggert <eggert@cs.ucla.edu>
+ boot-time,readutmp: do not depend on c-strtod
+ * lib/boot-time-aux.h (get_linux_uptime): Compute struct timespec
+ using integer arithmetic rather than double.
+ * lib/boot-time.c, lib/readutmp.c: Don’t include c-strtod.h.
+ * modules/boot-time, modules/readutmp (Depends-on): Remove c-strtod.
+
boot-time,readutmp: remove -lrt usage
This code uses clock-relevant functions only on platforms
that do not need -lrt.
{
buf[n] = '\0';
/* buf now contains two values: the uptime and the idle time. */
- char *endptr;
- double uptime = c_strtod (buf, &endptr);
- if (endptr > buf)
+ time_t s = 0;
+ char *p;
+ for (p = buf; '0' <= *p && *p <= '9'; p++)
+ s = 10 * s + (*p - '0');
+ if (buf < p)
{
- p_uptime->tv_sec = (time_t) uptime;
- p_uptime->tv_nsec = (uptime - p_uptime->tv_sec) * 1e9 + 0.5;
+ long ns = 0;
+ if (*p++ == '.')
+ for (int i = 0; i < 9; i++)
+ ns = 10 * ns + ('0' <= *p && *p <= '9' ? *p++ - '0' : 0);
+ p_uptime->tv_sec = s;
+ p_uptime->tv_nsec = ns;
return 0;
}
}
# include <OS.h>
#endif
-#include "c-strtod.h"
#include "idx.h"
#include "readutmp.h"
#include "stat-time.h"
# include <OS.h>
#endif
-#include "c-strtod.h"
#include "stat-time.h"
#include "xalloc.h"
m4/readutmp.m4
Depends-on:
-c-strtod
extensions
idx
stat-time
m4/systemd.m4
Depends-on:
-c-strtod
extensions
idx
stat-time