Thanks for catching that. Emacs would likely prefer not having to depend
on c-strtod so I installed the attached further patch.From 5528e726e9cc1ff9a2c7a71100450c52b65e9e7f Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 12 Aug 2023 16:54:51 -0700
Subject: [PATCH] boot-time,readutmp: do not depend on c-strtod
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 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 | 6 ++++++
lib/boot-time-aux.h | 16 +++++++++++-----
lib/boot-time.c | 1 -
lib/readutmp.c | 1 -
modules/boot-time | 1 -
modules/readutmp | 1 -
6 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9e5c65f564..252f302a59 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2023-08-12 Paul Eggert <egg...@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.
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 <OS.h>
#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 <OS.h>
#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
--
2.39.2