summaryrefslogtreecommitdiff
path: root/Python/fileutils.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-28 19:09:45 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-28 19:09:45 +0100
commit3a852cd214d726eb2bb96f94e498eda7ba042887 (patch)
tree71081d83765f4c721093b504ca9bd3b7673d41cd /Python/fileutils.c
parent07ee349b41ca8f94aadaf39be3ec9ca5aca692f9 (diff)
parent07b3714e5b40f0208a7640d315213a479d3742a0 (diff)
downloadcpython-3a852cd214d726eb2bb96f94e498eda7ba042887.tar.gz
Issue #7111: Python can now be run without a stdin, stdout or stderr stream.
It was already the case with Python 2. However, the corresponding sys module entries are now set to None (instead of an unusable file object).
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r--Python/fileutils.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index c563eaa5fb..0afa415d59 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -244,8 +244,12 @@ _Py_stat(PyObject *path, struct stat *statbuf)
#ifdef MS_WINDOWS
int err;
struct _stat wstatbuf;
+ wchar_t *wpath;
- err = _wstat(PyUnicode_AS_UNICODE(path), &wstatbuf);
+ wpath = PyUnicode_AsUnicode(path);
+ if (wpath == NULL)
+ return -1;
+ err = _wstat(wpath, &wstatbuf);
if (!err)
statbuf->st_mode = wstatbuf.st_mode;
return err;
@@ -297,14 +301,19 @@ FILE*
_Py_fopen(PyObject *path, const char *mode)
{
#ifdef MS_WINDOWS
+ wchar_t *wpath;
wchar_t wmode[10];
int usize;
+ wpath = PyUnicode_AsUnicode(path);
+ if (wpath == NULL)
+ return NULL;
+
usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode));
if (usize == 0)
return NULL;
- return _wfopen(PyUnicode_AS_UNICODE(path), wmode);
+ return _wfopen(wpath, wmode);
#else
FILE *f;
PyObject *bytes = PyUnicode_EncodeFSDefault(path);