From owner-freebsd-hackers@freebsd.org Fri Feb 16 19:29:40 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E381DF0AF43 for ; Fri, 16 Feb 2018 19:29:39 +0000 (UTC) (envelope-from leeb@ratnaling.org) Received: from mail-it0-x230.google.com (mail-it0-x230.google.com [IPv6:2607:f8b0:4001:c0b::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7AD916DCE2 for ; Fri, 16 Feb 2018 19:29:39 +0000 (UTC) (envelope-from leeb@ratnaling.org) Received: by mail-it0-x230.google.com with SMTP id o13so2990680ito.2 for ; Fri, 16 Feb 2018 11:29:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ratnaling-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=kpIO82StTtWmRj6vvFJGqHWwE6sPX+TGjuxe2S03Mj0=; b=iHxubR0asxcIn/BYvJwMdBRwQs5cJFVfTChMf4vG1ke9iX//StX9QwRsb7lO+G9ljl 5L3RAjIJHqT3Rumw9ir8bV3oUa+oSo/dv8ORtB1fwf5f1ley4H1S8nhw28U1hRthpfzO PJ13x5BHlcd0Aev79r9kQtwUwvzPzgTtuDdb5nha90Sb3DaWJgVilvcGgDOBbe1fYl6R BtyoOHJxLLo0sdvF2moVL6264mRwfIroGq9i2NoomYF9L6+8nVHEE9El4QT5pLrDW2HX iQaBlwHfw/U/3PkAbV4o4YloHpCsSn7INxegpMHPSML2uZED6u1SCh223vQY6CnIqPl2 bKJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=kpIO82StTtWmRj6vvFJGqHWwE6sPX+TGjuxe2S03Mj0=; b=p9gCOjYiXLj+P33fmM4l4hC6EmzIlcamHlCwqSFZkKNq4DO6xEnKzBzrbiI0Xd4CpQ UpMIZcCLEzxkGnOxQn7lT21CwvtCg8dkuQg379TSZmWOPSBydEj1PUYbWKWo7xlxA4Ha n7Rr99WS7tdk41/Y3KBqlTQKkzkunSebQPMqV9yYUVLUGtXXWG9VhIwbIqr3SucnWZSl OondykJM3bvOv5bJg4kJMrGyA3Y1mgtDzWi2kZrwzr9SLoelev+RDJaI2BoBgr4zcRwQ n+zXOr4+OFym6e+WDHJ0ZtMBUwGBj156DZDAypyncivhpNbKrBzw62ZB8a6TDXEakTU9 bVRw== X-Gm-Message-State: APf1xPCVbIsTKbBQnjNSBNxv0PcWs8+Pn0ou/xIf2jK9lRRiG+N9rvgI czEQRhVaXcm875mqG4rjZ/7TQx6fN7wkAAm2Pw/FG4AQ X-Google-Smtp-Source: AH8x226omVHaKlyW2dchQIk6nrO25RaNk4/TVQOCzUE3M5F5OyMwv0EFNZG8yz2Cxvu/KWLuY4mliWE8XhyQqfEDqZg= X-Received: by 10.36.208.4 with SMTP id m4mr10271462itg.69.1518809378580; Fri, 16 Feb 2018 11:29:38 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.225.66 with HTTP; Fri, 16 Feb 2018 11:29:37 -0800 (PST) In-Reply-To: References: From: Lee Brown Date: Fri, 16 Feb 2018 11:29:37 -0800 Message-ID: Subject: Re: How to set various locales with setlocale()? To: FreeBSD Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Feb 2018 19:29:40 -0000 On Fri, Feb 16, 2018 at 3:08 AM, Lee D 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 #include #include 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