Mercurial > cpython-lru_cache-weakref
diff Python/errors.c @ 74007:51412b4b81ae
Issue #13560: os.strerror() now uses the current locale encoding instead of UTF-8
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 17 Dec 2011 04:45:09 +0100 |
| parents | 021e5bb297d1 |
| children | 07802351ccad |
line wrap: on
line diff
--- a/Python/errors.c Sat Dec 17 04:13:41 2011 +0100 +++ b/Python/errors.c Sat Dec 17 04:45:09 2011 +0100 @@ -343,9 +343,7 @@ 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 @@ #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 */
