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

Skip to content

Commit b306d75

Browse files
author
Victor Stinner
committed
Fix fileutils for Windows
* Don't define _Py_wstat() on Windows, Windows has its own _wstat() function with a different API (the stat buffer has another type) * Include windows.h
1 parent e7c8083 commit b306d75

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

Include/fileutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PyAPI_FUNC(wchar_t *) _Py_char2wchar(
1111
PyAPI_FUNC(char*) _Py_wchar2char(
1212
const wchar_t *text);
1313

14-
#if defined(MS_WINDOWS) || defined(HAVE_STAT)
14+
#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
1515
PyAPI_FUNC(int) _Py_wstat(
1616
const wchar_t* path,
1717
struct stat *buf);

Python/fileutils.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "Python.h"
2+
#ifdef MS_WINDOWS
3+
# include <windows.h>
4+
#endif
25

36
#ifdef HAVE_STAT
47

@@ -183,20 +186,17 @@ _Py_wchar2char(const wchar_t *text)
183186
return result;
184187
}
185188

186-
#if defined(MS_WINDOWS) || defined(HAVE_STAT)
187-
int
188-
_Py_wstat(const wchar_t* path, struct stat *buf)
189-
{
190189
/* In principle, this should use HAVE__WSTAT, and _wstat
191190
should be detected by autoconf. However, no current
192191
POSIX system provides that function, so testing for
193192
it is pointless.
194193
Not sure whether the MS_WINDOWS guards are necessary:
195194
perhaps for cygwin/mingw builds?
196195
*/
197-
#ifdef MS_WINDOWS
198-
return _wstat(path, buf);
199-
#else
196+
#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
197+
int
198+
_Py_wstat(const wchar_t* path, struct stat *buf)
199+
{
200200
int err;
201201
char *fname;
202202
fname = _Py_wchar2char(path);
@@ -207,7 +207,6 @@ _Py_wstat(const wchar_t* path, struct stat *buf)
207207
err = stat(fname, buf);
208208
PyMem_Free(fname);
209209
return err;
210-
#endif
211210
}
212211
#endif
213212

0 commit comments

Comments
 (0)