aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2024-10-14 07:37:46 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2024-10-14 08:43:38 +0000
commitbd490be57438a82c22d1274bc58d51142b63f4a0 (patch)
tree5eee36ab171289203544be806168144d7001e821
parentbc7afab6a1fa4294df0b8d7d461bd0bdc542fbfe (diff)
downloadsrc-bd490be57438a82c22d1274bc58d51142b63f4a0.tar.gz
src-bd490be57438a82c22d1274bc58d51142b63f4a0.zip
w(1): fix libxo output being locale dependant
by being locale dependant the json export is invalid in locales where the separator for float is a comma. The Json and the XML are invalid for login-time when days contains contains characters which are not unicode. Forcing locale to be C, makes this json and xml output valid and also identical accross locales, so reliable for parsers PR: 276304 Reported by: Vedran Miletic <vedran@miletic.net>
-rw-r--r--usr.bin/w/w.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index 47899d0b38e0..ac1df96077d3 100644
--- a/usr.bin/w/w.c
+++ b/usr.bin/w/w.c
@@ -135,14 +135,16 @@ main(int argc, char *argv[])
char buf[MAXHOSTNAMELEN], fn[MAXHOSTNAMELEN];
char *dot;
- (void)setlocale(LC_ALL, "");
- use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
- use_comma = (*nl_langinfo(RADIXCHAR) != ',');
argc = xo_parse_args(argc, argv);
if (argc < 0)
exit(1);
+ if (xo_get_style(NULL) == XO_STYLE_TEXT) {
+ setlocale(LC_ALL, "");
+ }
+ use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
+ use_comma = (*nl_langinfo(RADIXCHAR) != ',');
/* Are we w(1) or uptime(1)? */
if (strcmp(basename(argv[0]), "uptime") == 0) {
wcmd = 0;