summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-03-18 16:54:18 +0000
committerJim Meyering <jim@meyering.net>2000-03-18 16:54:18 +0000
commit11f11947b5a564272c89e72671d0dd937c748424 (patch)
tree1c61c2c2266b32341e432b03ed6e2b4c614e6195
parent01c42af175dae168f9c03b5050908cd84a856b36 (diff)
downloadcoreutils-11f11947b5a564272c89e72671d0dd937c748424.tar.xz
(print_uptime): Use `buf' only if fgets succeeds.
-rw-r--r--src/uptime.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/uptime.c b/src/uptime.c
index 5a39ba649..084831fa7 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -63,14 +63,16 @@ print_uptime (int n, const STRUCT_UTMP *this)
{
char buf[BUFSIZ];
int res;
- fgets (buf, BUFSIZ, fp);
-
- /* The following sscanf must use the C locale. */
- setlocale (LC_NUMERIC, "C");
- res = sscanf (buf, "%lf", &upsecs);
- setlocale (LC_NUMERIC, "");
- if (res == 1)
- uptime = (time_t) upsecs;
+ char *b = fgets (buf, BUFSIZ, fp);
+ if (b == buf)
+ {
+ /* The following sscanf must use the C locale. */
+ setlocale (LC_NUMERIC, "C");
+ res = sscanf (buf, "%lf", &upsecs);
+ setlocale (LC_NUMERIC, "");
+ if (res == 1)
+ uptime = (time_t) upsecs;
+ }
fclose (fp);
}