git: 20f8331aca89 - main - usr.bin/stat: honour locale for "-t %+"

From: Stefan Eßer <se_at_FreeBSD.org>
Date: Sat, 30 Oct 2021 07:09:48 UTC
The branch main has been updated by se:

URL: https://cgit.FreeBSD.org/src/commit/?id=20f8331aca892ff812510609b3bc4e747b201197

commit 20f8331aca892ff812510609b3bc4e747b201197
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2021-10-30 07:00:34 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2021-10-30 07:00:34 +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.
    
    Reported by:    Jamie Landeg-Jones <jamie@catflap.org>
    MFC after:      3 days
---
 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 |