Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 19053:2bb242dc69d8 legacy-trunk
Patch #448227: Raise an exception when a directory is passed to execfile.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Wed, 08 Aug 2001 05:30:36 +0000 |
| parents | 09df3254b49d |
| children | f9494135b579 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Wed Aug 08 05:04:07 2001 +0000 +++ b/Python/bltinmodule.c Wed Aug 08 05:30:36 2001 +0000 @@ -568,6 +568,8 @@ PyObject *res; FILE* fp; PyCompilerFlags cf; + int exists; + struct stat s; if (!PyArg_ParseTuple(args, "s|O!O!:execfile", &filename, @@ -586,10 +588,27 @@ PyEval_GetBuiltins()) != 0) return NULL; } - Py_BEGIN_ALLOW_THREADS - fp = fopen(filename, "r"); - Py_END_ALLOW_THREADS - if (fp == NULL) { + + exists = 0; + /* Test for existence or directory. */ + if (!stat(filename, &s)) { + if (S_ISDIR(s.st_mode)) + errno = EISDIR; + else + exists = 1; + } + + if (exists) { + Py_BEGIN_ALLOW_THREADS + fp = fopen(filename, "r"); + Py_END_ALLOW_THREADS + + if (fp == NULL) { + exists = 0; + } + } + + if (!exists) { PyErr_SetFromErrno(PyExc_IOError); return NULL; }
