Skip to content

Commit c24db89

Browse files
Reuse is_extended_path()
1 parent df56cf3 commit c24db89

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎Modules/posixmodule.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,14 @@ win32_wchdir(LPCWSTR path)
20352035
#define HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES 1
20362036
#define HAVE_STRUCT_STAT_ST_REPARSE_TAG 1
20372037

2038+
/* The \\?\ prefix disables the path normalization, in particular
2039+
stripping of trailing dots and spaces. */
2040+
static int
2041+
is_extended_path(const wchar_t *path)
2042+
{
2043+
return wcsncmp(path, L"\\\\?\\", 4) == 0;
2044+
}
2045+
20382046
static void
20392047
find_data_to_file_info(WIN32_FIND_DATAW *pFileData,
20402048
FILE_BASIC_INFO* basic_info,
@@ -2109,9 +2117,9 @@ update_st_mode_from_path(const wchar_t *path, DWORD attr,
21092117
AccessCheck to check for generic read, write, and execute
21102118
access. */
21112119
size_t len = wcslen(path);
2112-
if (wcsncmp(path, L"\\\\?\\", 4) != 0) {
2120+
if (!is_extended_path(path)) {
21132121
/* Trailing dots and spaces are stripped from the last component
2114-
of the path, unless the \\?\ prefix disables normalization. */
2122+
of the path. */
21152123
while (len > 0 && (path[len - 1] == L'.' || path[len - 1] == L' ')) {
21162124
len--;
21172125
}
@@ -16719,12 +16727,6 @@ static PyType_Spec DirEntryType_spec = {
1671916727

1672016728
#ifdef MS_WINDOWS
1672116729

16722-
static int
16723-
is_extended_path(const wchar_t *path)
16724-
{
16725-
return wcsncmp(path, L"\\\\?\\", 4) == 0;
16726-
}
16727-
1672816730
static wchar_t *
1672916731
join_path_filenameW(const wchar_t *path_wide, const wchar_t *filename,
1673016732
int normalize)

0 commit comments

Comments
 (0)