提交 bd363c4b 编写于 作者: zzuli_lyw's avatar zzuli_lyw

Fix setlocale return value

Issue: https://gitee.com/openharmony/third_party_musl/issues/I7JK2Z

test: libc-test
Signed-off-by: zzuli_lyw's avatarzzulilyw <378305181@qq.com>
上级 acb871dc
......@@ -55,7 +55,7 @@ void duplocale_0200(void)
locale_t global = duplocale(LC_GLOBAL_LOCALE);
EXPECT_PTRNE("duplocale_0200", global, NULL);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "C.UTF-8", NULL);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "en_US", NULL);
EXPECT_PTRNE("duplocale_0200", newlocale_, NULL);
locale_t clonelocale = duplocale(newlocale_);
......
......@@ -39,8 +39,8 @@ void newlocale_0100(void)
EXPECT_PTRNE("newlocale_0100", lo, NULL);
return;
}
locale_t newlocale_ = newlocale(LC_ALL_MASK, "en-US", NULL);
EXPECT_PTREQ("newlocale_0100", newlocale_, NULL);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "en_US", NULL);
EXPECT_PTRNE("newlocale_0100", newlocale_, NULL);
if (newlocale_) {
freelocale(newlocale_);
......@@ -84,8 +84,8 @@ void newlocale_0300(void)
return;
}
for (int i = 0; i < sizeof(lcMarkArry) / sizeof(lcMarkArry[0]); i++) {
locale_t newlocale_ = newlocale(lcMarkArry[i], "en-US", NULL);
EXPECT_PTREQ("newlocale_0300", newlocale_, NULL);
locale_t newlocale_ = newlocale(lcMarkArry[i], "en_US", NULL);
EXPECT_PTRNE("newlocale_0300", newlocale_, NULL);
if (newlocale_) {
freelocale(newlocale_);
......
......@@ -55,7 +55,7 @@ void duplocale_0200(void)
locale_t global = duplocale(LC_GLOBAL_LOCALE);
EXPECT_PTRNE("duplocale_0200", global, NULL);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "C.UTF-8", NULL);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "en_US", NULL);
EXPECT_PTRNE("duplocale_0200", newlocale_, NULL);
locale_t clonelocale = duplocale(newlocale_);
......
......@@ -37,8 +37,8 @@ void newlocale_0100(void)
EXPECT_PTRNE("newlocale_0100", lo, NULL);
return;
}
locale_t newlocale_ = newlocale(LC_ALL_MASK, "en-US", NULL);
EXPECT_PTREQ("newlocale_0100", newlocale_, NULL);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "en_US", NULL);
EXPECT_PTRNE("newlocale_0100", newlocale_, NULL);
if (newlocale_) {
freelocale(newlocale_);
......@@ -81,8 +81,8 @@ void newlocale_0300(void)
return;
}
for (int i = 0; i < sizeof(lcMarkArry) / sizeof(lcMarkArry[0]); i++) {
locale_t newlocale_ = newlocale(lcMarkArry[i], "en-US", NULL);
EXPECT_PTREQ("newlocale_0300", newlocale_, NULL);
locale_t newlocale_ = newlocale(lcMarkArry[i], "en_US", NULL);
EXPECT_PTRNE("newlocale_0300", newlocale_, NULL);
if (newlocale_) {
freelocale(newlocale_);
......
......@@ -33,7 +33,7 @@ void wcsftime_l_0100(void)
wchar_t buffer[80];
time(&rtime);
timeinfo = localtime(&rtime);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "C.UTF-8", NULL);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "en_US", NULL);
size_t result = wcsftime_l(buffer, 80, L"%I:%M%p", timeinfo, newlocale_);
if (!result) {
t_error("%s wcsftime_l failed\n", __func__);
......@@ -60,7 +60,7 @@ void wcsftime_l_0200(void)
.tm_min = 10,
.tm_sec = 20,
};
locale_t newlocale_ = newlocale(LC_ALL_MASK, "C.UTF-8", NULL);
locale_t newlocale_ = newlocale(LC_ALL_MASK, "en_US", NULL);
size_t result = wcsftime_l(buff, sizeof buff, L"%A %c", &mtime, newlocale_);
if (!result) {
t_error("%s wcsftime_l failed\n", __func__);
......
......@@ -44,7 +44,7 @@ void strftime_l_0100(void)
return;
}
char buffer[gBufferSize];
locale_t m_locale = newlocale(LC_ALL_MASK, "C.UTF-8", NULL);
locale_t m_locale = newlocale(LC_ALL_MASK, "en_US", NULL);
strftime_l(buffer, sizeof(buffer) - 1, "%c", timeptr, m_locale);
EXPECT_STREQ("strftime_l_0100", buffer, test_asctime_data[i].result);
}
......
......@@ -74,8 +74,9 @@ const struct __locale_map *__get_locale(int cat, const char *val)
val = "C.UTF-8";
}
int builtin = (val[0]=='C' && !val[1])
|| !strcmp(val, "C.UTF-8")
|| !strcmp(val, "POSIX");
|| !strcmp(val, "POSIX")
|| !strcmp(val, "en")
|| !strcmp(val, "en_US");
if (builtin) {
if (cat == LC_CTYPE && val[1] == '.')
......@@ -89,6 +90,22 @@ const struct __locale_map *__get_locale(int cat, const char *val)
}
}
if (!strcmp(val, "en_US.UTF-8") || !strcmp(val, "C.UTF-8")) {
/* If no locale definition was found, make a locale map
* object anyway to store the name, which is kept for the
* sake of being able to do message translations at the
* application level. */
if (!new && (new = malloc(sizeof *new))) {
new->map = __c_dot_utf8.map;
new->map_size = __c_dot_utf8.map_size;
memcpy(new->name, val, n);
new->name[n] = 0;
new->next = loc_head;
new->flag = VALID;
loc_head = new;
}
}
if (!libc.secure) {
path = getenv("MUSL_LOCPATH");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册