| OLD | NEW |
| 1 | 1 |
| 2 /* POSIX module implementation */ | 2 /* POSIX module implementation */ |
| 3 | 3 |
| 4 /* This file is also used for Windows NT/MS-Win and OS/2. In that case the | 4 /* This file is also used for Windows NT/MS-Win and OS/2. In that case the |
| 5 module actually calls itself 'nt' or 'os2', not 'posix', and a few | 5 module actually calls itself 'nt' or 'os2', not 'posix', and a few |
| 6 functions are either unimplemented or implemented differently. The source | 6 functions are either unimplemented or implemented differently. The source |
| 7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent | 7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent |
| 8 of the compiler used. Different compilers define their own feature | 8 of the compiler used. Different compilers define their own feature |
| 9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. For OS/2, the compiler | 9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. For OS/2, the compiler |
| 10 independent macro PYOS_OS2 should be defined. On OS/2 the default | 10 independent macro PYOS_OS2 should be defined. On OS/2 the default |
| (...skipping 8477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8488 | 8488 |
| 8489 PyDoc_STRVAR(device_encoding__doc__, | 8489 PyDoc_STRVAR(device_encoding__doc__, |
| 8490 "device_encoding(fd) -> str\n\n\ | 8490 "device_encoding(fd) -> str\n\n\ |
| 8491 Return a string describing the encoding of the device\n\ | 8491 Return a string describing the encoding of the device\n\ |
| 8492 if the output is a terminal; else return None."); | 8492 if the output is a terminal; else return None."); |
| 8493 | 8493 |
| 8494 static PyObject * | 8494 static PyObject * |
| 8495 device_encoding(PyObject *self, PyObject *args) | 8495 device_encoding(PyObject *self, PyObject *args) |
| 8496 { | 8496 { |
| 8497 int fd; | 8497 int fd; |
| 8498 #if defined(MS_WINDOWS) || defined(MS_WIN64) |
| 8499 UINT cp; |
| 8500 #endif |
| 8498 if (!PyArg_ParseTuple(args, "i:device_encoding", &fd)) | 8501 if (!PyArg_ParseTuple(args, "i:device_encoding", &fd)) |
| 8499 return NULL; | 8502 return NULL; |
| 8500 if (!_PyVerify_fd(fd) || !isatty(fd)) { | 8503 if (!_PyVerify_fd(fd) || !isatty(fd)) { |
| 8501 Py_INCREF(Py_None); | 8504 Py_INCREF(Py_None); |
| 8502 return Py_None; | 8505 return Py_None; |
| 8503 } | 8506 } |
| 8504 #if defined(MS_WINDOWS) || defined(MS_WIN64) | 8507 #if defined(MS_WINDOWS) || defined(MS_WIN64) |
| 8505 if (fd == 0) { | 8508 if (fd == 0) |
| 8506 char buf[100]; | 8509 cp = GetConsoleCP(); |
| 8507 sprintf(buf, "cp%d", GetConsoleCP()); | 8510 else if (fd == 1 || fd == 2) |
| 8508 return PyUnicode_FromString(buf); | 8511 cp = GetConsoleOutputCP(); |
| 8509 } | 8512 else |
| 8510 if (fd == 1 || fd == 2) { | 8513 cp = 0; |
| 8511 char buf[100]; | 8514 /* GetConsoleCP() and GetConsoleOutputCP() return 0 if the application |
| 8512 sprintf(buf, "cp%d", GetConsoleOutputCP()); | 8515 has no console */ |
| 8513 return PyUnicode_FromString(buf); | 8516 if (cp != 0) |
| 8514 } | 8517 return PyUnicode_FromFormat("cp%u", (unsigned int)cp); |
| 8515 #elif defined(CODESET) | 8518 #elif defined(CODESET) |
| 8516 { | 8519 { |
| 8517 char *codeset = nl_langinfo(CODESET); | 8520 char *codeset = nl_langinfo(CODESET); |
| 8518 if (codeset != NULL && codeset[0] != 0) | 8521 if (codeset != NULL && codeset[0] != 0) |
| 8519 return PyUnicode_FromString(codeset); | 8522 return PyUnicode_FromString(codeset); |
| 8520 } | 8523 } |
| 8521 #endif | 8524 #endif |
| 8522 Py_INCREF(Py_None); | 8525 Py_INCREF(Py_None); |
| 8523 return Py_None; | 8526 return Py_None; |
| 8524 } | 8527 } |
| (...skipping 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10167 | 10170 |
| 10168 | 10171 |
| 10169 #endif /* __APPLE__ */ | 10172 #endif /* __APPLE__ */ |
| 10170 return m; | 10173 return m; |
| 10171 | 10174 |
| 10172 } | 10175 } |
| 10173 | 10176 |
| 10174 #ifdef __cplusplus | 10177 #ifdef __cplusplus |
| 10175 } | 10178 } |
| 10176 #endif | 10179 #endif |
| OLD | NEW |