summaryrefslogtreecommitdiffstats
path: root/usr.bin/w/pr_time.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/w/pr_time.c')
-rw-r--r--usr.bin/w/pr_time.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/usr.bin/w/pr_time.c b/usr.bin/w/pr_time.c
index 9fe0b11..4576b5e 100644
--- a/usr.bin/w/pr_time.c
+++ b/usr.bin/w/pr_time.c
@@ -52,13 +52,14 @@ static const char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 4/4/94";
* pr_attime --
* Print the time since the user logged in.
*/
-void
+int
pr_attime(time_t *started, time_t *now)
{
- static char buf[256];
+ static wchar_t buf[256];
struct tm tp, tm;
time_t diff;
- char fmt[20];
+ wchar_t *fmt;
+ int len, width, offset = 0;
tp = *localtime(started);
tm = *localtime(now);
@@ -66,7 +67,7 @@ pr_attime(time_t *started, time_t *now)
/* If more than a week, use day-month-year. */
if (diff > 86400 * 7)
- (void)strcpy(fmt, "%d%b%y");
+ fmt = L"%d%b%y";
/* If not today, use day-hour-am/pm. */
else if (tm.tm_mday != tp.tm_mday ||
@@ -74,16 +75,26 @@ pr_attime(time_t *started, time_t *now)
tm.tm_year != tp.tm_year) {
/* The line below does not take DST into consideration */
/* else if (*now / 86400 != *started / 86400) { */
- (void)strcpy(fmt, use_ampm ? "%a%I%p" : "%a%H");
+ fmt = use_ampm ? L"%a%I%p" : L"%a%H";
}
/* Default is hh:mm{am,pm}. */
else {
- (void)strcpy(fmt, use_ampm ? "%l:%M%p" : "%k:%M");
+ fmt = use_ampm ? L"%l:%M%p" : L"%k:%M";
}
- (void)strftime(buf, sizeof(buf), fmt, &tp);
- (void)wprintf(L"%-7.7s", buf);
+ (void)wcsftime(buf, sizeof(buf), fmt, &tp);
+ len = wcslen(buf);
+ width = wcswidth(buf, len);
+ if (len == width)
+ (void)wprintf(L"%-7.7ls", buf);
+ else if (width < 7)
+ (void)wprintf(L"%ls%.*s", buf, 7 - width, " ");
+ else {
+ (void)wprintf(L"%ls", buf);
+ offset = width - 7;
+ }
+ return (offset);
}
/*
OpenPOWER on IntegriCloud