Issue #13560: os.strerror() now uses the current locale encoding instead of UTF-8

This commit is contained in:
Victor Stinner 2011-12-17 04:45:09 +01:00
parent f2ea71fcc8
commit 1f33f2b0c3
5 changed files with 35 additions and 20 deletions

View file

@ -343,9 +343,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
PyObject *message;
PyObject *v, *args;
int i = errno;
#ifndef MS_WINDOWS
char *s;
#else
#ifdef MS_WINDOWS
WCHAR *s_buf = NULL;
#endif /* Unix/Windows */
@ -355,11 +353,14 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
#endif
#ifndef MS_WINDOWS
if (i == 0)
s = "Error"; /* Sometimes errno didn't get set */
else
s = strerror(i);
message = PyUnicode_DecodeUTF8(s, strlen(s), "ignore");
if (i != 0) {
char *s = strerror(i);
message = PyUnicode_DecodeLocale(s, 1);
}
else {
/* Sometimes errno didn't get set */
message = PyUnicode_FromString("Error");
}
#else
if (i == 0)
message = PyUnicode_FromString("Error"); /* Sometimes errno didn't get set */