Guido van Rossum added the comment:
> How do you like
> #ifdef MS_WINDOWS
> /* Remove trailing / and \ - Windows' stat doesn't like them
> - but
> * keep the trailing slash of C:/
> */
>
> Py_ssize_t i;
> char mangled[MAXPATHLEN+1];
>
> if (pathlen > MAXPATHLEN) {
> PyErr_SetString(PyExc_OverflowError,
> "path is too long");
> return -1;
> }
> strcpy(mangled, path);
>
> for (i = pathlen-1; i > 3; i--) {
> if (mangled[i] != '/' && mangled[i] != '\\') {
> break;
> }
> mangled[i] = '\0';
> }
> rv = stat(mangled, &statbuf);
> #else
> rv = stat(path, &statbuf);
> #endif
>
> i > 3 should take care of C:/ and C:\
But the C: is optional. You will need to do more parsing. Some more
examples (all with slashes; but backslashes work the same):
//share/ -> //share/
//share/x/ -> //share/x
/x/ -> /x
/ -> /
// -> // (probably illegal but doesn't matter)
C:/ -> C:/
x/ -> x
C:x/ -> C:x
Isn't it easier to handle this at the Python level? There probably
already is code for parsing Windows paths. (Hm, maybe we have it in C
too somewhere?)
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1293>
__________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com