diff options
author | wpaul <wpaul@FreeBSD.org> | 1995-11-21 05:43:27 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1995-11-21 05:43:27 +0000 |
commit | a5e133757a5a30846c2ec731d0205f89f6bff693 (patch) | |
tree | 5dfe7bcb07bad041d3be43328c56e554c6f414d6 | |
parent | 296fd04a468e6dbf5e79311e0ea4027a339c0c25 (diff) | |
download | FreeBSD-src-a5e133757a5a30846c2ec731d0205f89f6bff693.zip FreeBSD-src-a5e133757a5a30846c2ec731d0205f89f6bff693.tar.gz |
Amend my fix a bit. My way failed to take leap years into account. The
simplest thing is to just calculate the days using curtime - boottime / 86400.
The modification for this is less obtrusive anyway.
Suggested by: Bill Fenner <fenner@parc.xerox.com>
-rw-r--r-- | usr.bin/rup/rup.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/usr.bin/rup/rup.c b/usr.bin/rup/rup.c index c9b3365..8b34618e 100644 --- a/usr.bin/rup/rup.c +++ b/usr.bin/rup/rup.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: rup.c,v 1.2 1995/05/30 06:33:26 rgrimes Exp $"; +static char rcsid[] = "$Id$"; #endif /* not lint */ #include <stdio.h> @@ -95,7 +95,6 @@ rstat_reply(char *replyp, struct sockaddr_in *raddrp) struct hostent *hp; char *host; statstime *host_stat = (statstime *)replyp; - int year1, year2; if (search_host(raddrp->sin_addr)) return(0); @@ -116,21 +115,15 @@ rstat_reply(char *replyp, struct sockaddr_in *raddrp) tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec); host_time = *tmp_time; - tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec); - year1 = tmp_time->tm_year; - tmp_time = gmtime((time_t *)&host_stat->boottime.tv_sec); - year2 = tmp_time->tm_year; - host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec; tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec); host_uptime = *tmp_time; + #define updays (host_stat->curtime.tv_sec / 86400) if (host_uptime.tm_yday != 0) - sprintf(days_buf, "%3d day%s, ", host_uptime.tm_yday + - (365 * (year1 - year2)), - ((host_uptime.tm_yday + (365*(year1 - year2)))> 1) ? - "s" : ""); + sprintf(days_buf, "%3d day%s, ", updays, + (updays > 1) ? "s" : ""); else days_buf[0] = '\0'; |