summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-21 18:19:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-21 18:19:07 (GMT)
commit38425292fbb1811e78b02bbd190f6f4de75f6562 (patch)
treec10804e8f034bf9225dc7fa2f26d690a4fb3805d /Modules/posixmodule.c
parent3e62f78c4ef51972258b8f6bf76cb725cabddcad (diff)
downloadcpython-38425292fbb1811e78b02bbd190f6f4de75f6562.zip
cpython-38425292fbb1811e78b02bbd190f6f4de75f6562.tar.gz
cpython-38425292fbb1811e78b02bbd190f6f4de75f6562.tar.bz2
Issue #9908: Fix os.stat() on bytes paths under Windows 7.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 5969262..a3e106a 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1152,7 +1152,7 @@ win32_stat(const char* path, struct win32_stat *result)
NULL, /* security attributes */
OPEN_EXISTING,
/* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */
- FILE_FLAG_BACKUP_SEMANTICS,
+ FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS,
NULL);
if(hFile == INVALID_HANDLE_VALUE) {
@@ -1175,22 +1175,32 @@ win32_stat(const char* path, struct win32_stat *result)
}
code = attribute_data_to_stat(&info, result);
}
-
- buf_size = Py_GetFinalPathNameByHandleA(hFile, 0, 0, VOLUME_NAME_DOS);
- if(!buf_size) return -1;
- target_path = (char *)malloc((buf_size+1)*sizeof(char));
- result_length = Py_GetFinalPathNameByHandleA(hFile, target_path,
- buf_size, VOLUME_NAME_DOS);
-
- if(!result_length)
- return -1;
+ else {
+ /* We have a good handle to the target, use it to determine the target
+ path name (then we'll call lstat on it). */
+ buf_size = Py_GetFinalPathNameByHandleA(hFile, 0, 0, VOLUME_NAME_DOS);
+ if(!buf_size) return -1;
+ /* Due to a slight discrepancy between GetFinalPathNameByHandleA
+ and GetFinalPathNameByHandleW, we must allocate one more byte
+ than reported. */
+ target_path = (char *)malloc((buf_size+2)*sizeof(char));
+ result_length = Py_GetFinalPathNameByHandleA(hFile, target_path,
+ buf_size+1, VOLUME_NAME_DOS);
+
+ if(!result_length) {
+ free(target_path);
+ return -1;
+ }
- if(!CloseHandle(hFile))
- return -1;
+ if(!CloseHandle(hFile)) {
+ free(target_path);
+ return -1;
+ }
- target_path[result_length] = 0;
- code = win32_lstat(target_path, result);
- free(target_path);
+ target_path[result_length] = 0;
+ code = win32_lstat(target_path, result);
+ free(target_path);
+ }
return code;
}
@@ -1254,11 +1264,15 @@ win32_stat_w(const wchar_t* path, struct win32_stat *result)
result_length = Py_GetFinalPathNameByHandleW(hFile, target_path,
buf_size, VOLUME_NAME_DOS);
- if(!result_length)
+ if(!result_length) {
+ free(target_path);
return -1;
+ }
- if(!CloseHandle(hFile))
+ if(!CloseHandle(hFile)) {
+ free(target_path);
return -1;
+ }
target_path[result_length] = 0;
code = win32_lstat_w(target_path, result);