git: 98d3422e5ecd - stable/13 - usr.bin/stat: honour locale for "-t %+"

From: Stefan Eßer <se_at_FreeBSD.org>
Date: Fri, 04 Mar 2022 19:48:14 UTC
The branch stable/13 has been updated by se:

URL: https://cgit.FreeBSD.org/src/commit/?id=98d3422e5ecd96ea3ee83985a57a9399c0071663

commit 98d3422e5ecd96ea3ee83985a57a9399c0071663
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2021-10-30 07:00:34 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2022-03-04 19:43:01 +0000

    usr.bin/stat: honour locale for "-t %+"
    
    The man page states that "-t %+" prints time information in the same
    format as date with no format specifier.
    
    This was not the case, the format used was always that of date for the
    POSIX locale.
    
    The fix suggested by the reporter leads to output that matches the
    documentation.
    
    (cherry picked from commit 20f8331aca892ff812510609b3bc4e747b201197)
---
 usr.bin/stat/stat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c
index e504333c3329..9d94399a6333 100644
--- a/usr.bin/stat/stat.c
+++ b/usr.bin/stat/stat.c
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <grp.h>
 #include <limits.h>
+#include <locale.h>
 #include <paths.h>
 #include <pwd.h>
 #include <stdio.h>
@@ -763,6 +764,7 @@ format1(const struct stat *st,
 			ts.tv_sec = 0;
 			tm = localtime(&ts.tv_sec);
 		}
+		(void)setlocale(LC_TIME, "");
 		(void)strftime(path, sizeof(path), timefmt, tm);
 		sdata = path;
 		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |