]> Savannah Git Hosting - gnulib.git/commitdiff
boot-time,readutmp: do not depend on c-strtod
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Aug 2023 23:54:51 +0000 (16:54 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Aug 2023 23:55:16 +0000 (16:55 -0700)
* 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.

ChangeLog
lib/boot-time-aux.h
lib/boot-time.c
lib/readutmp.c
modules/boot-time
modules/readutmp

index 9e5c65f5649ce22e791961ab114c119fb49461a3..252f302a59ecff171b652ec83552be52e96d47c2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 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.
index d980682a5999fb4c81d9610376c57d16f4f7da5b..348611fc85c9d469072f94910a213bd6a5571a17 100644 (file)
@@ -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;
             }
         }
index 339ee8e938cb64b42c3392fbfbe49b7b96b0f6d6..d813bfa5825702f6ac249353b38c6831a216e11b 100644 (file)
@@ -43,7 +43,6 @@
 # include <OS.h>
 #endif
 
-#include "c-strtod.h"
 #include "idx.h"
 #include "readutmp.h"
 #include "stat-time.h"
index 6054511edfe0c3747d42b4587138b2c364662bd1..ef9f0aff43415f02b79479158bd980b23cc0cc8d 100644 (file)
@@ -51,7 +51,6 @@
 # include <OS.h>
 #endif
 
-#include "c-strtod.h"
 #include "stat-time.h"
 #include "xalloc.h"
 
index 24a798160a80e02e131007fbdf5063652d286526..2d89969d5caed3f0beb8312d9161ef9a9153fb87 100644 (file)
@@ -9,7 +9,6 @@ lib/readutmp.h
 m4/readutmp.m4
 
 Depends-on:
-c-strtod
 extensions
 idx
 stat-time
index 304cebca0c4d6f24e3e77fea055a7162e2432b8a..469a7c22561e32b706e6dbcb64dea98eced0b763 100644 (file)
@@ -9,7 +9,6 @@ m4/readutmp.m4
 m4/systemd.m4
 
 Depends-on:
-c-strtod
 extensions
 idx
 stat-time