aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2001-03-02 23:53:36 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2001-03-02 23:53:36 +0000
commit080175194f04811695cecf5174116a6e2077d62e (patch)
treec9edddabcd4e8247cb710d249271b5ac1250a1bc
parent5f2de0a78a6a82f8cc6f97df29ecc6cfb0771caf (diff)
downloadsrc-080175194f04811695cecf5174116a6e2077d62e.tar.gz
src-080175194f04811695cecf5174116a6e2077d62e.zip
Use AM/PM time only when available in locale
Notes
Notes: svn path=/head/; revision=73367
-rw-r--r--bin/ps/extern.h2
-rw-r--r--bin/ps/print.c6
-rw-r--r--bin/ps/ps.c5
3 files changed, 9 insertions, 4 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index dedac7ee5921..55796699d435 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -41,7 +41,7 @@ struct varent;
extern fixpt_t ccpu;
extern int eval, fscale, mempages, nlistread, rawcpu, cflag;
-extern int sumrusage, termwidth, totwidth;
+extern int sumrusage, termwidth, totwidth, use_ampm;
extern VAR var[];
extern VARENT *vhead;
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 72d96cfa41e9..37d03a382821 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -366,9 +366,11 @@ started(k, ve)
if (!now)
(void)time(&now);
if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
- (void)strftime(buf, sizeof(buf) - 1, "%l:%M%p", tp);
+ (void)strftime(buf, sizeof(buf) - 1,
+ use_ampm ? "%l:%M%p" : "%k:%M ", tp);
} else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
- (void)strftime(buf, sizeof(buf) - 1, "%a%I%p", tp);
+ (void)strftime(buf, sizeof(buf) - 1,
+ use_ampm ? "%a%I%p" : "%a%H ", tp);
} else
(void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
(void)printf("%-*s", v->width, buf);
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 324ff6bbff16..7d5aaeebbd4a 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -58,14 +58,15 @@ static const char rcsid[] =
#include <errno.h>
#include <fcntl.h>
#include <kvm.h>
+#include <langinfo.h>
#include <limits.h>
+#include <locale.h>
#include <nlist.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <locale.h>
#include <pwd.h>
#include <utmp.h>
@@ -82,6 +83,7 @@ int rawcpu; /* -C */
int sumrusage; /* -S */
int termwidth; /* width of screen (0 == infinity) */
int totwidth; /* calculated width of requested variables */
+int use_ampm; /* use AM/PM time */
static int needuser, needcomm, needenv;
#if defined(LAZY_PS)
@@ -129,6 +131,7 @@ main(argc, argv)
char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX];
(void) setlocale(LC_ALL, "");
+ use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&