Index: usr.bin/w/w.c =================================================================== --- usr.bin/w/w.c +++ usr.bin/w/w.c @@ -472,7 +472,12 @@ struct timespec tp; int days, hrs, i, mins, secs; char buf[256]; + char *upbuf, *tmpbuf; + upbuf = malloc(256); + memset(upbuf, '\0', 256); + tmpbuf = malloc(256); + memset(upbuf, '\0', 256); /* * Print time of day. */ @@ -494,20 +499,31 @@ secs = uptime % 60; xo_emit(" up"); xo_attr("seconds", "%lu", (unsigned long) tp.tv_sec); - if (days > 0) - xo_emit(" {:uptime/%d day%s},", + xo_emit("{e:uptime_seconds/%lu}", (unsigned long) tp.tv_sec); + xo_emit("{e:days/%d}{e:hours/%d}{e:minutes/%d}{e:seconds/%d}", days, hrs, mins, secs); + + if (days > 0) { + sprintf(tmpbuf, "%d day%s,", days, days > 1 ? "s" : ""); - if (hrs > 0 && mins > 0) - xo_emit(" {:uptime/%2d:%02d},", hrs, mins); - else if (hrs > 0) - xo_emit(" {:uptime/%d hr%s},", + upbuf = strcat(upbuf, tmpbuf); + } + if (hrs > 0 && mins > 0) { + sprintf(tmpbuf, " %2d:%02d,", hrs, mins); + upbuf = strcat(upbuf, tmpbuf); + } else if (hrs > 0) { + sprintf(tmpbuf, " %d hr%s,", hrs, hrs > 1 ? "s" : ""); - else if (mins > 0) - xo_emit(" {:uptime/%d min%s},", + upbuf = strcat(upbuf, tmpbuf); + } else if (mins > 0) { + sprintf(tmpbuf, " %d min%s,", mins, mins > 1 ? "s" : ""); - else - xo_emit(" {:uptime/%d sec%s},", + upbuf = strcat(upbuf, tmpbuf); + } else { + sprintf(tmpbuf, " %d sec%s,", secs, secs > 1 ? "s" : ""); + upbuf = strcat(upbuf, tmpbuf); + } + xo_emit("{:uptime/%s}", upbuf); } /* Print number of users logged in to system */