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
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ PyAPI_FUNC(char*) Py_EncodeLocale(
1515
const wchar_t *text,
1616
size_t *error_pos);
1717

18-
PyAPI_FUNC(int) _Py_wstat(
19-
const wchar_t* path,
20-
struct stat *buf);
21-
2218
#ifndef Py_LIMITED_API
2319

2420
#ifdef MS_WINDOWS

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
Original file line numberDiff line numberDiff line change
@@ -520,23 +520,6 @@ Py_EncodeLocale(const wchar_t *text, size_t *error_pos)
520520
}
521521

522522

523-
/* Get file status. Encode the path to the locale encoding. */
524-
int
525-
_Py_wstat(const wchar_t* path, struct stat *buf)
526-
{
527-
int err;
528-
char *fname;
529-
fname = Py_EncodeLocale(path, NULL);
530-
if (fname == NULL) {
531-
errno = EINVAL;
532-
return -1;
533-
}
534-
err = stat(fname, buf);
535-
PyMem_Free(fname);
536-
return err;
537-
}
538-
539-
540523
#ifdef MS_WINDOWS
541524
static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 and 1.1.1970 */
542525

0 commit comments

Comments
 (0)