<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, Dec 1, 2024 at 1:08 AM Rob Landley <<a href="mailto:rob@landley.net">rob@landley.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 11/30/24 11:28, Ray Gardner wrote:<br>
> Toybox main.c has this code to support UTF-8:<br>
> <br>
>      // Try user's locale, but if that isn't UTF-8 merge in a UTF-8 locale's<br>
>      // character type data. (Fall back to en_US for MacOS.)<br>
>      setlocale(LC_CTYPE, "");<br>
>      if (strcmp("UTF-8", nl_langinfo(CODESET)))<br>
>        uselocale(newlocale(LC_CTYPE_MASK, "C.UTF-8", 0) ? :<br>
>          newlocale(LC_CTYPE_MASK, "en_US.UTF-8", 0));<br>
<br>
Which is basically result of many long arguments trying to get Android, <br>
MacOS, and various Linux distros (glibc and musl but also differing <br>
locale installation choices) to play nice with each other.<br>
<br>
> For a standalone version of awk, I intend to use this instead:<br>
> <br>
>    char *p = setlocale(LC_CTYPE, "");<br>
>    if (!p || !strstr(p, "UTF-8")) p = setlocale(LC_CTYPE, "C.UTF-8");<br>
>    if (!p || !strstr(p, "UTF-8")) p = setlocale(LC_CTYPE, "en_US.UTF-8");<br>
> <br>
> Rationale is that this compiles on older systems that lack up to date<br>
> locale support.<br>
<br>
Good luck?<br>
<br>
<a href="https://landley.net/toybox/faq.html#support_horizon" rel="noreferrer" target="_blank">https://landley.net/toybox/faq.html#support_horizon</a><br>
<br>
> What will be the effective difference between these? I am not familiar<br>
> with the details of locale support in C and POSIX.<br>
<br>
That's probably a question for Elliott. (Or possibly Rich Felker.)<br></blockquote><div><br></div><div>i think it's really a question for someone who knows something about whatever [presumably ancient] systems you're trying to support. bionic and musl are both always utf-8, glibc and macOS let you test with nl_langinfo(3), and i don't think i've used anything that wasn't one of those since the 1990s...</div><div><br></div><div>nl_langinfo(3) has been in posix since issue 2, so i'd assume historical systems without that also aren't going to understand _anything_ you try to do to convince them to use utf8?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
According to "git annotate main.c" that code is a combination of commits <br>
b34ed8132, 75b89012c, and bec202875 and the dates on those commits <br>
incriminate various mailing list threads ala <br>
<a href="http://lists.landley.net/pipermail/toybox-landley.net/2020-December/028293.html" rel="noreferrer" target="_blank">http://lists.landley.net/pipermail/toybox-landley.net/2020-December/028293.html</a> <br>
and <br>
<a href="http://lists.landley.net/pipermail/toybox-landley.net/2023-February/029452.html" rel="noreferrer" target="_blank">http://lists.landley.net/pipermail/toybox-landley.net/2023-February/029452.html</a> <br>
and probably more. (And that's before I dig further back to see how we <br>
got THERE. I remember arguing about C vs C.utf8 locale support in 2013, <br>
because I remember what office break room I was checking email in and <br>
that contract only lasted 6 months...)<br>
<br>
Rob<br>
_______________________________________________<br>
Toybox mailing list<br>
<a href="mailto:Toybox@lists.landley.net" target="_blank">Toybox@lists.landley.net</a><br>
<a href="http://lists.landley.net/listinfo.cgi/toybox-landley.net" rel="noreferrer" target="_blank">http://lists.landley.net/listinfo.cgi/toybox-landley.net</a><br>
</blockquote></div></div>