From: Paul Eggert Date: Sat, 12 Aug 2023 23:54:51 +0000 (-0700) Subject: boot-time,readutmp: do not depend on c-strtod X-Git-Tag: v1.0~917 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=5528e726e9cc1ff9a2c7a71100450c52b65e9e7f;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 9e5c65f564..252f302a59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2023-08-12 Paul Eggert + 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. diff --git a/lib/boot-time-aux.h b/lib/boot-time-aux.h index d980682a59..348611fc85 100644 --- a/lib/boot-time-aux.h +++ b/lib/boot-time-aux.h @@ -47,12 +47,18 @@ get_linux_uptime (struct timespec *p_uptime) { 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; } } diff --git a/lib/boot-time.c b/lib/boot-time.c index 339ee8e938..d813bfa582 100644 --- a/lib/boot-time.c +++ b/lib/boot-time.c @@ -43,7 +43,6 @@ # include #endif -#include "c-strtod.h" #include "idx.h" #include "readutmp.h" #include "stat-time.h" diff --git a/lib/readutmp.c b/lib/readutmp.c index 6054511edf..ef9f0aff43 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -51,7 +51,6 @@ # include #endif -#include "c-strtod.h" #include "stat-time.h" #include "xalloc.h" diff --git a/modules/boot-time b/modules/boot-time index 24a798160a..2d89969d5c 100644 --- a/modules/boot-time +++ b/modules/boot-time @@ -9,7 +9,6 @@ lib/readutmp.h m4/readutmp.m4 Depends-on: -c-strtod extensions idx stat-time diff --git a/modules/readutmp b/modules/readutmp index 304cebca0c..469a7c2256 100644 --- a/modules/readutmp +++ b/modules/readutmp @@ -9,7 +9,6 @@ m4/readutmp.m4 m4/systemd.m4 Depends-on: -c-strtod extensions idx stat-time