Use a global `now' variable for the current time, and initialise it at

startup, right after calling setlocale(3).
This commit is contained in:
Juli Mallett 2002-06-06 21:21:25 +00:00
parent 76e1a9fe48
commit ba2cd77062
3 changed files with 5 additions and 6 deletions

View File

@ -42,6 +42,7 @@ struct varent;
extern fixpt_t ccpu;
extern int cflag, eval, fscale, mempages, nlistread, rawcpu;
extern int sumrusage, termwidth, totwidth;
extern time_t now;
extern VARENT *vhead;
__BEGIN_DECLS

View File

@ -376,7 +376,6 @@ void
started(KINFO *k, VARENT *ve)
{
VAR *v;
static time_t now;
time_t then;
struct tm *tp;
char buf[100];
@ -393,8 +392,6 @@ started(KINFO *k, VARENT *ve)
then = k->ki_p->ki_start.tv_sec;
tp = localtime(&then);
if (!now)
(void)time(&now);
if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
(void)strftime(buf, sizeof(buf) - 1,
use_ampm ? "%l:%M%p" : "%k:%M ", tp);
@ -541,12 +538,9 @@ elapsed(KINFO *k, VARENT *ve)
VAR *v;
time_t secs;
char obuff[128];
static time_t now;
v = ve->var;
if (!now)
time(&now);
secs = now - k->ki_p->ki_start.tv_sec;
(void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld", secs/60, secs%60);
(void)printf("%*s", v->width, obuff);

View File

@ -81,6 +81,8 @@ int sumrusage; /* -S */
int termwidth; /* width of screen (0 == infinity) */
int totwidth; /* calculated width of requested variables */
time_t now; /* current time(3) value */
static int needuser, needcomm, needenv;
#if defined(LAZY_PS)
static int forceuread=0;
@ -128,6 +130,8 @@ main(int argc, char *argv[])
const char *nlistf, *memf;
(void) setlocale(LC_ALL, "");
/* Set the time to what it is right now. */
time(&now);
if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0')
termwidth = atoi(cols);