Issue #23753: Move _Py_wstat() from Python/fileutils.c to Modules/get… · pythoncapi/cpython@91afbb6 · GitHub
Skip to content

Commit 91afbb6

Browse files
committed
Issue python#23753: Move _Py_wstat() from Python/fileutils.c to Modules/getpath.c
I expected more users of _Py_wstat(), but in practice it's only used by Modules/getpath.c. Move the function because it's not needed on Windows. Windows uses PC/getpathp.c which uses the Win32 API (ex: GetFileAttributesW()) not the POSIX API.
1 parent 10dc484 commit 91afbb6

3 files changed

Lines changed: 17 additions & 21 deletions

File tree

Include/fileutils.h

Lines changed: 0 additions & 4 deletions

Modules/getpath.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ static wchar_t exec_prefix[MAXPATHLEN+1];
131131
static wchar_t progpath[MAXPATHLEN+1];
132132
static wchar_t *module_search_path = NULL;
133133

134+
/* Get file status. Encode the path to the locale encoding. */
135+
136+
static int
137+
_Py_wstat(const wchar_t* path, struct stat *buf)
138+
{
139+
int err;
140+
char *fname;
141+
fname = Py_EncodeLocale(path, NULL);
142+
if (fname == NULL) {
143+
errno = EINVAL;
144+
return -1;
145+
}
146+
err = stat(fname, buf);
147+
PyMem_Free(fname);
148+
return err;
149+
}
150+
134151
static void
135152
reduce(wchar_t *dir)
136153
{

Python/fileutils.c

Lines changed: 0 additions & 17 deletions

0 commit comments

Comments
 (0)