mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
Add fake support for locale="" (#546)
This commit is contained in:
parent
6c3048821c
commit
27416e7dd6
2 changed files with 34 additions and 2 deletions
|
@ -17,16 +17,18 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Sets program locale.
|
||||
*
|
||||
* Cosmopolitan only supports the C or POSIX locale.
|
||||
*
|
||||
* "You can have any locale you want as long as it's C." -- Henry Ford
|
||||
*/
|
||||
char *setlocale(int category, const char *locale) {
|
||||
if (!locale) return "C";
|
||||
if (!locale || (*locale == '\0')) return "C";
|
||||
if (!strcmp(locale, "C") || !strcmp(locale, "POSIX")) {
|
||||
return locale;
|
||||
} else {
|
||||
|
|
30
test/libc/str/setlocale_test.c
Normal file
30
test/libc/str/setlocale_test.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Gavin Arthur Hayes │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(setlocale, test) {
|
||||
EXPECT_STREQ("C", setlocale(LC_ALL, NULL));
|
||||
EXPECT_STREQ("C", setlocale(LC_ALL, "C"));
|
||||
EXPECT_STREQ("C", setlocale(LC_ALL, NULL));
|
||||
EXPECT_STREQ("POSIX", setlocale(LC_ALL, "POSIX"));
|
||||
EXPECT_STREQ("C", setlocale(LC_ALL, ""));
|
||||
EXPECT_EQ(0, setlocale(LC_ALL, "ja_JP.PCK"));
|
||||
EXPECT_STREQ("C", setlocale(LC_ALL, NULL));
|
||||
}
|
Loading…
Reference in a new issue