[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
readutmp, boot-time: Fix parsing of /proc/uptime
From: |
Bruno Haible |
Subject: |
readutmp, boot-time: Fix parsing of /proc/uptime |
Date: |
Sun, 13 Aug 2023 00:12:25 +0200 |
/proc/uptime contains a floating-point number with '.' as decimal separator.
It thus needs to be parsed with 'c_strtod', not 'strtod' (which expects a ','
on French and German locales).
2023-08-12 Bruno Haible <bruno@clisp.org>
readutmp, boot-time: Fix parsing of /proc/uptime.
* lib/boot-time-aux.h (get_linux_uptime): Use c_strtod, not strtod.
* lib/readutmp.c: Include c-strtod.h.
* lib/boot-time.c: Likewise.
* modules/readutmp (Depends-on): Add c-strtod.
* modules/boot-time (Depends-on): Likewise.
diff --git a/lib/boot-time-aux.h b/lib/boot-time-aux.h
index e9f58e9d7e..4c5474c6c8 100644
--- a/lib/boot-time-aux.h
+++ b/lib/boot-time-aux.h
@@ -48,7 +48,7 @@ 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 = strtod (buf, &endptr);
+ double uptime = c_strtod (buf, &endptr);
if (endptr > buf)
{
p_uptime->tv_sec = (time_t) uptime;
diff --git a/lib/boot-time.c b/lib/boot-time.c
index d813bfa582..339ee8e938 100644
--- a/lib/boot-time.c
+++ b/lib/boot-time.c
@@ -43,6 +43,7 @@
# 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 ef9f0aff43..6054511edf 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -51,6 +51,7 @@
# 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 ba8a2b4e6f..8890406d6c 100644
--- a/modules/boot-time
+++ b/modules/boot-time
@@ -9,6 +9,7 @@ lib/readutmp.h
m4/readutmp.m4
Depends-on:
+c-strtod
extensions
fopen-gnu
idx
diff --git a/modules/readutmp b/modules/readutmp
index 85bbf74954..fcbc7ff149 100644
--- a/modules/readutmp
+++ b/modules/readutmp
@@ -9,6 +9,7 @@ m4/readutmp.m4
m4/systemd.m4
Depends-on:
+c-strtod
extensions
fopen-gnu
idx
- readutmp, boot-time: Fix parsing of /proc/uptime,
Bruno Haible <=