diff options
author | Thomas Heller <theller@ctypes.org> | 2007-07-12 11:03:13 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2007-07-12 11:03:13 (GMT) |
commit | af2be262af836eb1d8cb1a555d1640d5e0bfef86 (patch) | |
tree | b20f1b378d3a224820705944de4c962eb7e0528f /Modules/_fileio.c | |
parent | 5fa3f0517b072d6e864d33cfc4fe3f53ea02c702 (diff) | |
download | cpython-af2be262af836eb1d8cb1a555d1640d5e0bfef86.zip cpython-af2be262af836eb1d8cb1a555d1640d5e0bfef86.tar.gz cpython-af2be262af836eb1d8cb1a555d1640d5e0bfef86.tar.bz2 |
First part of sf# 1752225: Support for wide filenames on Windows.
Patch by Amaury Forgeot d'Arc.
Diffstat (limited to 'Modules/_fileio.c')
-rw-r--r-- | Modules/_fileio.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c index feae513..a2c0221 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -118,7 +118,9 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) char *name = NULL; char *mode = "r"; char *s; - int wideargument = 0; +#ifdef MS_WINDOWS + Py_UNICODE *widename = NULL; +#endif int ret = 0; int rwa = 0, plus = 0, append = 0; int flags = 0; @@ -151,20 +153,16 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) PyObject *po; if (PyArg_ParseTupleAndKeywords(args, kwds, "U|s:fileio", kwlist, &po, &mode)) { - wideargument = 1; + widename = PyUnicode_AS_UNICODE(po); } else { /* Drop the argument parsing error as narrow strings are also valid. */ PyErr_Clear(); } - - PyErr_SetString(PyExc_NotImplementedError, - "Windows wide filenames are not yet supported"); - goto error; } + if (widename == NULL) #endif - - if (!wideargument) { + { if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|s:fileio", kwlist, Py_FileSystemDefaultEncoding, @@ -174,7 +172,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) } self->readable = self->writable = 0; - self->seekable = -1; + self->seekable = -1; s = mode; while (*s) { switch (*s++) { @@ -241,6 +239,11 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) else { Py_BEGIN_ALLOW_THREADS errno = 0; +#ifdef MS_WINDOWS + if (widename != NULL) + self->fd = _wopen(widename, flags, 0666); + else +#endif self->fd = open(name, flags, 0666); Py_END_ALLOW_THREADS if (self->fd < 0 || dircheck(self) < 0) { |