Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix printing non-(ASCII/UTF-8) strings #68

Closed
wants to merge 1 commit into from
Closed

Fix printing non-(ASCII/UTF-8) strings #68

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 25, 2019

As reported in FreeBSD's PR241491, ps(1) using libxo does not display the
date in uk_UA.KOI8-U locale when invoked as ps -o lstart and prints
empty lines instead. To fix it we need to assume that %s is passed in
current locale encoding.

  • use XF_ENC_LOCALE for 's' format character
  • pass "" to setlocale() so that if the consumer actually called setlocale()
    itself we don't overwrite already set locale; current order of environment
    variables differs from at least FreeBSD's setlocale() where the following
    order is used:
    LC_ALL
    LC_*
    LANG

As reported in FreeBSD's PR241491, ps(1) using libxo does not display the
date in uk_UA.KOI8-U locale when invoked as `ps -o lstart` and prints
empty lines instead.  To fix it we need to assume that %s is passed in
current locale encoding.

- use XF_ENC_LOCALE for 's' format character
- pass "" to setlocale() so that if the consumer actually called setlocale()
  itself we don't overwrite already set locale; current order of environment
  variables differs from at least FreeBSD's setlocale() where the following
  order is used:
    LC_ALL
    LC_*
    LANG
@philshafer
Copy link

philshafer commented Oct 26, 2019 via email

@ghost
Copy link
Author

ghost commented Oct 26, 2019

On Oct 25, 2019, at 6:06 PM, Yuri Pankov @.***> wrote: To fix it we need to assume that %s is passed in current locale encoding.
The “%s” format does not mean “current locale”. If ps wants that, it needs to use “%hs”. “%s” means UTF-8: https://libxo.readthedocs.io/en/latest/field-formatting.html#utf-8-and-locale-strings https://libxo.readthedocs.io/en/latest/field-formatting.html#utf-8-and-locale-strings

Got it, and sorry, that the first time I looked at libxo specific issue. I'll close this one and will fix the ps instead, thanks!

Re: the admittedly strange arg to setlocale(), my testing found that “” didn’t pick up the environment settings, so I coded it explicitly. If the order doesn’t follow the FreeBSD specs, I can repair it. Is this order documented somewhere in the FreeBSD docs?

Not that I know of, the code for reference: https://svnweb.freebsd.org/base/head/lib/libc/locale/setlocale.c?revision=326025&view=markup#l285.

And if you could provide a bit more info on "" not working (possibly as PR), that would be helpful!

@ghost ghost closed this Oct 26, 2019
@philshafer
Copy link

philshafer commented Oct 29, 2019 via email

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant