bpo-31904: Add encoding support for VxWorks RTOS (GH-12051)
Use UTF-8 as the system encoding on VxWorks.
The main reason are:
1. The locale is frequently misconfigured.
2. Missing some functions to deal with locale in VxWorks C library.
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index e1bf8b5..c3eccb3 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -1280,7 +1280,7 @@
#ifdef MS_WINDOWS
char encoding[20];
PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());
-#elif defined(__ANDROID__)
+#elif defined(__ANDROID__) || defined(__VXWORKS__)
const char *encoding = "UTF-8";
#else
const char *encoding = nl_langinfo(CODESET);
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 366bd00..75e015a 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -536,7 +536,7 @@
int current_locale, _Py_error_handler errors)
{
if (current_locale) {
-#ifdef __ANDROID__
+#if defined(__ANDROID__) || defined(__VXWORKS__)
return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason,
errors);
#else
@@ -544,7 +544,7 @@
#endif
}
-#if defined(__APPLE__) || defined(__ANDROID__)
+#if defined(__APPLE__) || defined(__ANDROID__) || defined(__VXWORKS__)
return _Py_DecodeUTF8Ex(arg, strlen(arg), wstr, wlen, reason,
errors);
#else
@@ -569,7 +569,7 @@
#endif
return decode_current_locale(arg, wstr, wlen, reason, errors);
-#endif /* __APPLE__ or __ANDROID__ */
+#endif /* __APPLE__ or __ANDROID__ or __VXWORKS__ */
}