Chi Hsuan Yen added the comment:

There are some locale strings supported in setlocale(): 
https://android.googlesource.com/platform/bionic/+/master/libc/bionic/locale.cpp#104.
 However, seems mbstowcs just ignores such a setting on Android. Here's an 
example:

#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#define BUFFER_SIZE 10

void test_mbstowcs()
{
    wchar_t dest[BUFFER_SIZE];
    memset(dest, 0, sizeof(dest));
    printf("mbstowcs: %ld\n", mbstowcs(dest, "中文", BUFFER_SIZE));
    printf("dest: %x %x\n", dest[0], dest[1]);
}

int main()
{
    printf("setlocale: %d\n",  setlocale(LC_ALL, "en_US.UTF-8") != NULL);
    test_mbstowcs();
    printf("setlocale: %d\n",  setlocale(LC_ALL, "C") != NULL);
    test_mbstowcs();
    return 0;
}

On Linux (glibc 2.24) the result is:

$ ./a.out 
setlocale: 1
mbstowcs: 2
dest: 4e2d 6587
setlocale: 1
mbstowcs: -1
dest: 0 0

On Android (6.0 Marshmallow) the result is:
shell@ASUS_Z00E_2:/ $ /data/local/tmp/a.out
setlocale: 1
mbstowcs: 2
dest: 4e2d 6587
setlocale: 1
mbstowcs: 2
dest: 4e2d 6587

A quick search indicates setlocale() affects *scanf functions only, so I guess 
it's safe to force UTF-8 in CPython.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26928>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to