Message57179
> 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?) |
|
| Date |
User |
Action |
Args |
| 2007-11-06 20:19:38 | gvanrossum | set | spambayes_score: 0.0464389 -> 0.0464389 recipients:
+ gvanrossum, brett.cannon, georg.brandl, facundobatista, christian.heimes, guillaumegirard |
| 2007-11-06 20:19:38 | gvanrossum | link | issue1293 messages |
| 2007-11-06 20:19:38 | gvanrossum | create | |
|