Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Feb 2018 11:29:37 -0800
From:      Lee Brown <leeb@ratnaling.org>
To:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: How to set various locales with setlocale()?
Message-ID:  <CAFPNf5-1OH1e2rEWJGcj49wHXHZirjbY4Ap2zmisd4FSL6z=kQ@mail.gmail.com>
In-Reply-To: <CANC_bnOgf%2BFA5adpkh2Fvap7m_3zL=APgSge9s34h18EaBk-nQ@mail.gmail.com>
References:  <CANC_bnOgf%2BFA5adpkh2Fvap7m_3zL=APgSge9s34h18EaBk-nQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Feb 16, 2018 at 3:08 AM, Lee D <embaudarm@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 =3D setlocale(LC_ALL,"en_US.US-ASCII");
 char buf[100];
 time(&now);

 strftime(buf,99,"%c",localtime(&now));
 printf("%s\n", buf);

 s =3D 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
=E9=80=B1=E4=BA=94  2=E6=9C=88/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@apron.ad.nyingma.org:/usr/obj/usr/src/sys/GENERIC
amd64



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFPNf5-1OH1e2rEWJGcj49wHXHZirjbY4Ap2zmisd4FSL6z=kQ>