From nobody Mon Oct 11 17:04:51 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 69343181455E; Mon, 11 Oct 2021 17:04:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HSlXM5SkFz4VBp; Mon, 11 Oct 2021 17:04:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9623524C22; Mon, 11 Oct 2021 17:04:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19BH4pfU036651; Mon, 11 Oct 2021 17:04:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19BH4p75036649; Mon, 11 Oct 2021 17:04:51 GMT (envelope-from git) Date: Mon, 11 Oct 2021 17:04:51 GMT Message-Id: <202110111704.19BH4p75036649@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: 902cde5d0a62 - main - Revert "last(1): unbreak for 8-bit locales" List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 902cde5d0a620a502468a95f7eecf1098e96bdcc Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=902cde5d0a620a502468a95f7eecf1098e96bdcc commit 902cde5d0a620a502468a95f7eecf1098e96bdcc Author: Piotr Pawel Stefaniak AuthorDate: 2021-10-10 06:37:36 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2021-10-11 17:01:57 +0000 Revert "last(1): unbreak for 8-bit locales" This reverts commits 8e67c427b5 (unbreak for 8-bit locales), 0ca58ca151 (correction after r351413), and f424ec1b80 (fix style after r351459). A simpler fix can be done by using the h modifier for strings that are encoded with the current locale. Reviewed by: eugen, philip Differential Revision: https://reviews.freebsd.org/D32437 --- usr.bin/last/last.c | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c index d197afe7eb0b..188f393ae3fc 100644 --- a/usr.bin/last/last.c +++ b/usr.bin/last/last.c @@ -92,7 +92,6 @@ static const char *crmsg; /* cause of last reboot */ static time_t currentout; /* current logout value */ static long maxrec; /* records to display */ static const char *file = NULL; /* utx.log file */ -static int noctfix = 0; /* locale is C or UTF-8 */ static int sflag = 0; /* show delta in seconds */ static int width = 5; /* show seconds in delta */ static int yflag; /* show year */ @@ -104,7 +103,6 @@ static time_t snaptime; /* if != 0, we will only */ static void addarg(int, char *); -static const char *ctf(const char *); static time_t dateconv(char *); static void doentry(struct utmpx *); static void hostconv(char *); @@ -114,31 +112,6 @@ static int want(struct utmpx *); static void usage(void); static void wtmp(void); -static const char* -ctf(const char *fmt) { - static char buf[31]; - const char *src, *end; - char *dst; - - if (noctfix) - return (fmt); - - end = buf + sizeof(buf); - for (src = fmt, dst = buf; dst < end; *dst++ = *src++) { - if (*src == '\0') { - *dst = '\0'; - break; - } else if (*src == '%' && *(src+1) == 's') { - *dst++ = '%'; - *dst++ = 'h'; - *dst++ = 's'; - strlcpy(dst, src+2, end - dst); - return (buf); - } - } - return (buf); -} - static void usage(void) { @@ -157,11 +130,6 @@ main(int argc, char *argv[]) (void) setlocale(LC_TIME, ""); d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); - (void) setlocale(LC_CTYPE, ""); - p = nl_langinfo(CODESET); - if (strcmp(p, "UTF-8") == 0 || strcmp(p, "US-ASCII") == 0) - noctfix = 1; - argc = xo_parse_args(argc, argv); if (argc < 0) exit(1); @@ -294,7 +262,7 @@ wtmp(void) (void) strftime(ct, sizeof(ct), "%+", tm); xo_emit("\n{:utxdb/%s}", (file == NULL) ? "utx.log" : file); xo_attr("seconds", "%lu", (unsigned long) t); - xo_emit(ctf(" begins {:begins/%s}\n"), ct); + xo_emit(" begins {:begins/%s}\n", ct); xo_close_container("last-information"); } @@ -411,7 +379,7 @@ printentry(struct utmpx *bp, struct idtab *tt) break; } xo_attr("seconds", "%lu", (unsigned long)t); - xo_emit(ctf(" {:login-time/%s%c/%s}"), ct, tt == NULL ? '\n' : ' '); + xo_emit(" {:login-time/%s%c/%s}", ct, tt == NULL ? '\n' : ' '); if (tt == NULL) goto end; if (!tt->logout) { @@ -425,7 +393,7 @@ printentry(struct utmpx *bp, struct idtab *tt) tm = localtime(&tt->logout); (void) strftime(ct, sizeof(ct), "%R", tm); xo_attr("seconds", "%lu", (unsigned long)tt->logout); - xo_emit(ctf("- {:logout-time/%s}"), ct); + xo_emit("- {:logout-time/%s}", ct); } delta = tt->logout - bp->ut_tv.tv_sec; xo_attr("seconds", "%ld", (long)delta); @@ -435,9 +403,9 @@ printentry(struct utmpx *bp, struct idtab *tt) tm = gmtime(&delta); (void) strftime(ct, sizeof(ct), width >= 8 ? "%T" : "%R", tm); if (delta < 86400) - xo_emit(ctf(" ({:session-length/%s})\n"), ct); + xo_emit(" ({:session-length/%s})\n", ct); else - xo_emit(ctf(" ({:session-length/%ld+%s})\n"), + xo_emit(" ({:session-length/%ld+%s})\n", (long)delta / 86400, ct); }