diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-07-06 16:48:24 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-07-06 16:48:24 (GMT) |
commit | 9235b254dcad979abe36be1024f8e89b04c764be (patch) | |
tree | 21333ef9c9b354715db5d029da445f5209bb9227 /Modules | |
parent | 01cca5e45185474bdb3c621c5dec4bfc0b323483 (diff) | |
download | cpython-9235b254dcad979abe36be1024f8e89b04c764be.zip cpython-9235b254dcad979abe36be1024f8e89b04c764be.tar.gz cpython-9235b254dcad979abe36be1024f8e89b04c764be.tar.bz2 |
Issue #15247: FileIO now raises an error when given a file descriptor pointing to a directory.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/fileio.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index a7fad36..605ad51 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -166,22 +166,15 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds) directories, so we need a check. */ static int -dircheck(fileio* self, const char *name) +dircheck(fileio* self, PyObject *nameobj) { #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) struct stat buf; if (self->fd < 0) return 0; if (fstat(self->fd, &buf) == 0 && S_ISDIR(buf.st_mode)) { - char *msg = strerror(EISDIR); - PyObject *exc; - if (internal_close(self)) - return -1; - - exc = PyObject_CallFunction(PyExc_IOError, "(iss)", - EISDIR, msg, name); - PyErr_SetObject(PyExc_IOError, exc); - Py_XDECREF(exc); + errno = EISDIR; + PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, nameobj); return -1; } #endif @@ -373,9 +366,9 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); goto error; } - if (dircheck(self, name) < 0) - goto error; } + if (dircheck(self, nameobj) < 0) + goto error; #if defined(MS_WINDOWS) || defined(__CYGWIN__) /* don't translate newlines (\r\n <=> \n) */ |