diff options
author | ume <ume@FreeBSD.org> | 2009-08-30 11:17:42 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2009-08-30 11:17:42 +0000 |
commit | 5fb95a2095446b02c21f0e4ecad4b7bff41c856a (patch) | |
tree | 7bf9aeb96248569d4de361589958b5bc4732cbe8 /usr.bin/w/pr_time.c | |
parent | 7417f9bcd242fe20479c87d0e5f24840616ab1d3 (diff) | |
download | FreeBSD-src-5fb95a2095446b02c21f0e4ecad4b7bff41c856a.zip FreeBSD-src-5fb95a2095446b02c21f0e4ecad4b7bff41c856a.tar.gz |
Fix the problem that the entry broke into two lines with multi-byte
AM/PM format.
Reported by: takawata
Diffstat (limited to 'usr.bin/w/pr_time.c')
-rw-r--r-- | usr.bin/w/pr_time.c | 27 |
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); } /* |