diff options
author | Guido van Rossum <guido@python.org> | 2000-04-21 18:54:45 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-04-21 18:54:45 (GMT) |
commit | ace88aebbbbb5c96eb3dd88308d03d3d3b9c73e5 (patch) | |
tree | 6f0e96a723fdda92a52434ea57869ed9ab1aede3 /Modules/posixmodule.c | |
parent | e0cd291b8123859191cbef90316d55b39e4ce3a1 (diff) | |
download | cpython-ace88aebbbbb5c96eb3dd88308d03d3d3b9c73e5.zip cpython-ace88aebbbbb5c96eb3dd88308d03d3d3b9c73e5.tar.gz cpython-ace88aebbbbb5c96eb3dd88308d03d3d3b9c73e5.tar.bz2 |
Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
backslash from the pathname argument to stat() on Windows -- while on
Unix, stat("/bin/") succeeds and does the same thing as stat("/bin"),
on Windows, stat("\\windows\\") fails while stat("\\windows") succeeds.
This modified version of the patch recognizes both / and \.
(This is odd behavior of the MS C library, since
os.listdir("\\windows\\") succeeds!)
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c948b95..e269106 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -549,8 +549,36 @@ posix_do_stat(self, args, format, statfunc) struct stat st; char *path; int res; + +#ifdef MS_WIN32 + int pathlen; + char pathcopy[MAX_PATH]; +#endif /* MS_WIN32 */ + if (!PyArg_ParseTuple(args, format, &path)) return NULL; + +#ifdef MS_WIN32 + pathlen = strlen(path); + /* the library call can blow up if the file name is too long! */ + if (pathlen > MAX_PATH) { + errno = ENAMETOOLONG; + return posix_error(); + } + + if ((pathlen > 0) && (path[pathlen-1] == '\\' || path[pathlen-1] == '/')) { + /* exception for drive root */ + if (!((pathlen == 3) && + (path[1] == ':') && + (path[2] == '\\' || path[2] == '/'))) + { + strncpy(pathcopy, path, pathlen); + pathcopy[pathlen-1] = '\0'; /* nuke the trailing backslash */ + path = pathcopy; + } + } +#endif /* MS_WIN32 */ + Py_BEGIN_ALLOW_THREADS res = (*statfunc)(path, &st); Py_END_ALLOW_THREADS |