This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients brett.cannon, christian.heimes, facundobatista, georg.brandl, guillaumegirard, gvanrossum
Date 2007-11-06.20:19:38
SpamBayes Score 0.0464389
Marked as misclassified No
Message-id <ca471dc20711061219n21d7c711y5d53efcc31e4c232@mail.gmail.com>
In-reply-to <4730C99A.9080205@cheimes.de>
Content
> 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?)
History
Date User Action Args
2007-11-06 20:19:38gvanrossumsetspambayes_score: 0.0464389 -> 0.0464389
recipients: + gvanrossum, brett.cannon, georg.brandl, facundobatista, christian.heimes, guillaumegirard
2007-11-06 20:19:38gvanrossumlinkissue1293 messages
2007-11-06 20:19:38gvanrossumcreate