How to set various locales with setlocale()?
Lee Brown
leeb at ratnaling.org
Fri Feb 16 19:29:40 UTC 2018
On Fri, Feb 16, 2018 at 3:08 AM, Lee D <embaudarm at gmail.com> wrote:
> Hi,
>
> I have a C program that needs to print the date in the correct form
> for the appropriate locale.
>
> Unfortunately, setlocale() will not accept any of the locale names in
> /usr/share/locale/, (which is documented in the man page for
> setlocale()).
>
> This is an embedded program running on custom arm hardware, not a
> normal user system, so I am trying to do everything from within the C
> program. Setting an environment variable and rebooting would be
> cumbersome.
>
> Do you folks have any suggestions on how to accomplish this goal, or
> how to make setlocale accept the locales listed on the system?
>
>
> Different architecture, it works as advertised. Maybe ask the arm folks?
$ cat a.c
#include <time.h>
#include <stdio.h>
#include <locale.h>
int main() {
time_t now;
char *s;
s = setlocale(LC_ALL,"en_US.US-ASCII");
char buf[100];
time(&now);
strftime(buf,99,"%c",localtime(&now));
printf("%s\n", buf);
s = setlocale(LC_ALL,"zh_TW.UTF-8");
strftime(buf,99,"%c",localtime(&now));
printf("%s\n", buf);
}
$ cc a.c
$ ./a.out
Fri Feb 16 11:26:58 2018
週五 2月/16 11:26:58 2018
FreeBSD apron.ad.nyingma.org 11.1-RELEASE-p6 FreeBSD 11.1-RELEASE-p6 #0
r328506M: Sat Jan 27 23:09:57 PST 2018
root at apron.ad.nyingma.org:/usr/obj/usr/src/sys/GENERIC
amd64
More information about the freebsd-hackers
mailing list