Message57178
| Author |
christian.heimes |
| Recipients |
brett.cannon, christian.heimes, facundobatista, georg.brandl, guillaumegirard, gvanrossum |
| Date |
2007年11月06日.20:07:55 |
| SpamBayes Score |
0.07686064 |
| Marked as misclassified |
No |
| Message-id |
<4730C99A.9080205@cheimes.de> |
| In-reply-to |
<1194376204.36.0.627339998478.issue1293@psf.upfronthosting.co.za> |
| Content |
Guido van Rossum wrote:
> (1) Don't use s#; it will allow null bytes in the string, which we don't
> want.
>
> (2) Put the entire trailing slash removal inside #ifdef MS_WINDOWS.
Done aand done
> (3) Careful! It seems the code you wrote would transform "C:/" into
> "C:" which isn't the same thing (the latter refers to the current
> directory on the C drive, while the former is the root of the C drive).
Oh, good catch! I haven't thought of C:/
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:\
Christian |
|