diff options
author | jmallett <jmallett@FreeBSD.org> | 2002-06-06 21:21:25 +0000 |
---|---|---|
committer | jmallett <jmallett@FreeBSD.org> | 2002-06-06 21:21:25 +0000 |
commit | d11731ff431780a9d55268d2c478bdd517945657 (patch) | |
tree | d00aa5fbf24ccd496e1bb92817a26f8752ec7a80 /bin | |
parent | becd81c4a9315cc0cfd6078a89434a5ed7091e28 (diff) | |
download | FreeBSD-src-d11731ff431780a9d55268d2c478bdd517945657.zip FreeBSD-src-d11731ff431780a9d55268d2c478bdd517945657.tar.gz |
Use a global `now' variable for the current time, and initialise it at
startup, right after calling setlocale(3).
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ps/extern.h | 1 | ||||
-rw-r--r-- | bin/ps/print.c | 6 | ||||
-rw-r--r-- | bin/ps/ps.c | 4 |
3 files changed, 5 insertions, 6 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h index 927343c..4bae792 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -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 diff --git a/bin/ps/print.c b/bin/ps/print.c index 4f43aa4..7864cae 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -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); diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 2a25c92..f808cd5 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -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); |