* [PATCH 1/2] * tests/test-getloadavg.c (main): Fix typo.
@ 2020-06-27 16:56 Paul Eggert
2020-06-27 16:56 ` [PATCH 2/2] getloadavg: don’t depend on fopen-gnu Paul Eggert
0 siblings, 1 reply; 2+ messages in thread
From: Paul Eggert @ 2020-06-27 16:56 UTC (permalink / raw)
To: bug-gnulib; +Cc: Paul Eggert
---
ChangeLog | 4 ++++
tests/test-getloadavg.c | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index eb3b4bc8f..cd194e0c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2020-06-27 Paul Eggert <eggert@cs.ucla.edu>
+
+ * tests/test-getloadavg.c (main): Fix typo.
+
2020-06-27 Bruno Haible <bruno@clisp.org>
tempname et al.: Fix link errors on MSVC (regression from 2020-05-31).
diff --git a/tests/test-getloadavg.c b/tests/test-getloadavg.c
index daf443b61..b8782c2c3 100644
--- a/tests/test-getloadavg.c
+++ b/tests/test-getloadavg.c
@@ -70,7 +70,7 @@ main (int argc, char **argv)
if (loads > 1)
check_avg (5, avg[1], argc > 1);
if (loads > 2)
- check_avg (15, avg[1], argc > 1);
+ check_avg (15, avg[2], argc > 1);
if (loads > 0 && argc > 1)
putchar ('\n');
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] getloadavg: don’t depend on fopen-gnu
2020-06-27 16:56 [PATCH 1/2] * tests/test-getloadavg.c (main): Fix typo Paul Eggert
@ 2020-06-27 16:56 ` Paul Eggert
0 siblings, 0 replies; 2+ messages in thread
From: Paul Eggert @ 2020-06-27 16:56 UTC (permalink / raw)
To: bug-gnulib; +Cc: Paul Eggert
This is for Emacs, which does not need fopen-gnu for anything else,
and which would need it only on a NetBSD platform where getloadavg
does not work (does that even happen?).
* lib/getloadavg.c (getloadavg) [__NetBSD__]: Use open, not fopen.
* modules/getloadavg (Depends-on): Remove fopen-gnu.
---
ChangeLog | 7 +++++++
lib/getloadavg.c | 21 ++++++++++++++-------
modules/getloadavg | 1 -
3 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cd194e0c4..19e609e31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2020-06-27 Paul Eggert <eggert@cs.ucla.edu>
+ getloadavg: don’t depend on fopen-gnu
+ This is for Emacs, which does not need fopen-gnu for anything else,
+ and which would need it only on a NetBSD platform where getloadavg
+ does not work (does that even happen?).
+ * lib/getloadavg.c (getloadavg) [__NetBSD__]: Use open, not fopen.
+ * modules/getloadavg (Depends-on): Remove fopen-gnu.
+
* tests/test-getloadavg.c (main): Fix typo.
2020-06-27 Bruno Haible <bruno@clisp.org>
diff --git a/lib/getloadavg.c b/lib/getloadavg.c
index aeb7070cc..468e25067 100644
--- a/lib/getloadavg.c
+++ b/lib/getloadavg.c
@@ -567,15 +567,22 @@ getloadavg (double loadavg[], int nelem)
unsigned long int load_ave[3], scale;
int count;
- FILE *fp;
-
- fp = fopen (NETBSD_LDAV_FILE, "re");
- if (fp == NULL)
- return -1;
- count = fscanf (fp, "%lu %lu %lu %lu\n",
+ char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1];
+ int fd = open (NETBSD_LDAV_FILE, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return fd;
+ int nread = read (fd, readbuf, sizeof readbuf - 1);
+ int err = errno;
+ close (fd);
+ if (nread < 0)
+ {
+ errno = err;
+ return -1;
+ }
+ readbuf[nread] = '\0';
+ count = sscanf (readbuf, "%lu %lu %lu %lu\n",
&load_ave[0], &load_ave[1], &load_ave[2],
&scale);
- (void) fclose (fp);
if (count != 4)
{
errno = ENOTSUP;
diff --git a/modules/getloadavg b/modules/getloadavg
index a5a3c4e03..8adb9a784 100644
--- a/modules/getloadavg
+++ b/modules/getloadavg
@@ -7,7 +7,6 @@ m4/getloadavg.m4
Depends-on:
extensions
-fopen-gnu
intprops
open
stdbool
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-27 16:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 16:56 [PATCH 1/2] * tests/test-getloadavg.c (main): Fix typo Paul Eggert
2020-06-27 16:56 ` [PATCH 2/2] getloadavg: don’t depend on fopen-gnu Paul Eggert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).