Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0bb44a4

Browse files
committed
Closes SF bug 113894: on Windows, things like os.listdir("k:") and
glob.glob("k:*py") (i.e., a raw drive letter + colon at the start) were using the root of the drive rather than the expected Windows behavior of using the drive's "current directory".
1 parent a2ebb87 commit 0bb44a4

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

Modules/posixmodule.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ posix_listdir(PyObject *self, PyObject *args)
796796
HANDLE hFindFile;
797797
WIN32_FIND_DATA FileData;
798798
char namebuf[MAX_PATH+5];
799+
char ch;
799800

800801
if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len))
801802
return NULL;
@@ -804,7 +805,8 @@ posix_listdir(PyObject *self, PyObject *args)
804805
return NULL;
805806
}
806807
strcpy(namebuf, name);
807-
if (namebuf[len-1] != '/' && namebuf[len-1] != '\\')
808+
ch = namebuf[len-1];
809+
if (ch != '/' && ch != '\\' && ch != ':')
808810
namebuf[len++] = '/';
809811
strcpy(namebuf + len, "*.*");
810812

@@ -844,8 +846,7 @@ posix_listdir(PyObject *self, PyObject *args)
844846

845847
return d;
846848

847-
#else /* !MS_WIN32 */
848-
#ifdef _MSC_VER /* 16-bit Windows */
849+
#elif defined(_MSC_VER) /* 16-bit Windows */
849850

850851
#ifndef MAX_PATH
851852
#define MAX_PATH 250
@@ -906,8 +907,7 @@ posix_listdir(PyObject *self, PyObject *args)
906907

907908
return d;
908909

909-
#else
910-
#if defined(PYOS_OS2)
910+
#elif defined(PYOS_OS2)
911911

912912
#ifndef MAX_PATH
913913
#define MAX_PATH CCHMAXPATH
@@ -1016,10 +1016,8 @@ posix_listdir(PyObject *self, PyObject *args)
10161016

10171017
return d;
10181018

1019-
#endif /* !PYOS_OS2 */
1020-
#endif /* !_MSC_VER */
1021-
#endif /* !MS_WIN32 */
1022-
}
1019+
#endif /* which OS */
1020+
} /* end of posix_listdir */
10231021

10241022
static char posix_mkdir__doc__[] =
10251023
"mkdir(path [, mode=0777]) -> None\n\

0 commit comments

Comments
 (0)