summaryrefslogtreecommitdiff
path: root/Python/fileutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r--Python/fileutils.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index d1d62dce5d..582c6bafd8 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -93,6 +93,10 @@ _Py_device_encoding(int fd)
return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
#else
+ if (_PyRuntime.preconfig.utf8_mode) {
+ _Py_DECLARE_STR(utf_8, "utf-8");
+ return Py_NewRef(&_Py_STR(utf_8));
+ }
return _Py_GetLocaleEncodingObject();
#endif
}
@@ -873,10 +877,10 @@ _Py_EncodeLocaleEx(const wchar_t *text, char **str,
// Get the current locale encoding name:
//
-// - Return "UTF-8" if _Py_FORCE_UTF8_LOCALE macro is defined (ex: on Android)
-// - Return "UTF-8" if the UTF-8 Mode is enabled
+// - Return "utf-8" if _Py_FORCE_UTF8_LOCALE macro is defined (ex: on Android)
+// - Return "utf-8" if the UTF-8 Mode is enabled
// - On Windows, return the ANSI code page (ex: "cp1250")
-// - Return "UTF-8" if nl_langinfo(CODESET) returns an empty string.
+// - Return "utf-8" if nl_langinfo(CODESET) returns an empty string.
// - Otherwise, return nl_langinfo(CODESET).
//
// Return NULL on memory allocation failure.
@@ -888,12 +892,8 @@ _Py_GetLocaleEncoding(void)
#ifdef _Py_FORCE_UTF8_LOCALE
// On Android langinfo.h and CODESET are missing,
// and UTF-8 is always used in mbstowcs() and wcstombs().
- return _PyMem_RawWcsdup(L"UTF-8");
+ return _PyMem_RawWcsdup(L"utf-8");
#else
- const PyPreConfig *preconfig = &_PyRuntime.preconfig;
- if (preconfig->utf8_mode) {
- return _PyMem_RawWcsdup(L"UTF-8");
- }
#ifdef MS_WINDOWS
wchar_t encoding[23];
@@ -906,7 +906,7 @@ _Py_GetLocaleEncoding(void)
if (!encoding || encoding[0] == '\0') {
// Use UTF-8 if nl_langinfo() returns an empty string. It can happen on
// macOS if the LC_CTYPE locale is not supported.
- return _PyMem_RawWcsdup(L"UTF-8");
+ return _PyMem_RawWcsdup(L"utf-8");
}
wchar_t *wstr;