Message57178
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 |
|
| Date |
User |
Action |
Args |
| 2007-11-06 20:07:56 | christian.heimes | set | spambayes_score: 0.0768606 -> 0.0768606 recipients:
+ christian.heimes, gvanrossum, brett.cannon, georg.brandl, facundobatista, guillaumegirard |
| 2007-11-06 20:07:55 | christian.heimes | link | issue1293 messages |
| 2007-11-06 20:07:55 | christian.heimes | create | |
|