diff options
author | Jim Meyering <jim@meyering.net> | 2004-02-05 09:51:49 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-02-05 09:51:49 +0000 |
commit | ad669dfe92c422900a7838cea0e1bb7831ef6940 (patch) | |
tree | 4bd40dbb2b20f9758a92c4215360ca3581d04ce3 /src/uptime.c | |
parent | c904b0cae656e1850ce5ce33e92e82ff76211df4 (diff) | |
download | coreutils-ad669dfe92c422900a7838cea0e1bb7831ef6940.tar.xz |
Don't dump core if localtime returns NULL (possible on
hosts with 64-bit time_t and 32-bit int).
Print "??" if the current clock can't
be converted by localtime. This won't happen until the year
2*31 + 1900, but we don't want to dump core even if the current
clock has the wrong value.
Diffstat (limited to 'src/uptime.c')
-rw-r--r-- | src/uptime.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/uptime.c b/src/uptime.c index 652b256e8..3c746f57b 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -132,11 +132,14 @@ print_uptime (int n, const STRUCT_UTMP *this) uphours = (uptime - (updays * 86400)) / 3600; upmins = (uptime - (updays * 86400) - (uphours * 3600)) / 60; tmn = localtime (&time_now); - printf (_(" %2d:%02d%s up "), ((tmn->tm_hour % 12) == 0 - ? 12 : tmn->tm_hour % 12), - /* FIXME: use strftime, not am, pm. Uli reports that - the german translation is meaningless. */ - tmn->tm_min, (tmn->tm_hour < 12 ? _("am") : _("pm"))); + if (tmn) + printf (_(" %2d:%02d%s up "), + ((tmn->tm_hour % 12) == 0 ? 12 : tmn->tm_hour % 12), + /* FIXME: use strftime, not am, pm. Uli reports that + the german translation is meaningless. */ + tmn->tm_min, (tmn->tm_hour < 12 ? _("am") : _("pm"))); + else + printf (_(" ??:???? up ")); if (updays > 0) printf (ngettext("%d day", "%d days", updays), updays); printf (" %2d:%02d, ", uphours, upmins); |