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 20f8331aca)
This commit is contained in:
Stefan Eßer 2021-10-30 09:00:34 +02:00
parent 6f9036a651
commit 98d3422e5e

View file

@ -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 |