Christian Heimes added the comment:

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

__________________________________
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

Reply via email to