@@ -180,9 +180,9 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
180180static int
181181check_fd (int fd )
182182{
183- #if defined(HAVE_FSTAT )
184- struct stat buf ;
185- if (!_PyVerify_fd (fd ) || (fstat (fd , & buf ) < 0 && errno == EBADF )) {
183+ #if defined(HAVE_FSTAT ) || defined( MS_WINDOWS )
184+ struct _Py_stat_struct buf ;
185+ if (!_PyVerify_fd (fd ) || (_Py_fstat (fd , & buf ) < 0 && errno == EBADF )) {
186186 PyObject * exc ;
187187 char * msg = strerror (EBADF );
188188 exc = PyObject_CallFunction (PyExc_OSError , "(is)" ,
@@ -222,8 +222,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
222222#elif !defined(MS_WINDOWS )
223223 int * atomic_flag_works = NULL ;
224224#endif
225- #ifdef HAVE_FSTAT
226- struct stat fdfstat ;
225+ #if defined( HAVE_FSTAT ) || defined( MS_WINDOWS )
226+ struct _Py_stat_struct fdfstat ;
227227#endif
228228 int async_err = 0 ;
229229
@@ -420,9 +420,11 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
420420 }
421421
422422 self -> blksize = DEFAULT_BUFFER_SIZE ;
423- #ifdef HAVE_FSTAT
424- if (fstat (self -> fd , & fdfstat ) < 0 )
423+ #if defined(HAVE_FSTAT ) || defined(MS_WINDOWS )
424+ if (_Py_fstat (self -> fd , & fdfstat ) < 0 ) {
425+ PyErr_SetFromErrno (PyExc_OSError );
425426 goto error ;
427+ }
426428#if defined(S_ISDIR ) && defined(EISDIR )
427429 /* On Unix, open will succeed for directories.
428430 In Python, there should be no file objects referring to
@@ -437,7 +439,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
437439 if (fdfstat .st_blksize > 1 )
438440 self -> blksize = fdfstat .st_blksize ;
439441#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
440- #endif /* HAVE_FSTAT */
442+ #endif /* HAVE_FSTAT || MS_WINDOWS */
441443
442444#if defined(MS_WINDOWS ) || defined(__CYGWIN__ )
443445 /* don't translate newlines (\r\n <=> \n) */
@@ -603,17 +605,7 @@ fileio_readinto(fileio *self, PyObject *args)
603605 return PyLong_FromSsize_t (n );
604606}
605607
606- #ifndef HAVE_FSTAT
607-
608- static PyObject *
609- fileio_readall (fileio * self )
610- {
611- _Py_IDENTIFIER (readall );
612- return _PyObject_CallMethodId ((PyObject * )& PyRawIOBase_Type ,
613- & PyId_readall , "O" , self );
614- }
615-
616- #else
608+ #if defined(HAVE_FSTAT ) || defined(MS_WINDOWS )
617609
618610static size_t
619611new_buffersize (fileio * self , size_t currentsize )
@@ -637,7 +629,7 @@ new_buffersize(fileio *self, size_t currentsize)
637629static PyObject *
638630fileio_readall (fileio * self )
639631{
640- struct stat st ;
632+ struct _Py_stat_struct st ;
641633 Py_off_t pos , end ;
642634 PyObject * result ;
643635 Py_ssize_t bytes_read = 0 ;
@@ -655,7 +647,7 @@ fileio_readall(fileio *self)
655647#else
656648 pos = lseek (self -> fd , 0L , SEEK_CUR );
657649#endif
658- if (fstat (self -> fd , & st ) == 0 )
650+ if (_Py_fstat (self -> fd , & st ) == 0 )
659651 end = st .st_size ;
660652 else
661653 end = (Py_off_t )- 1 ;
@@ -729,7 +721,17 @@ fileio_readall(fileio *self)
729721 return result ;
730722}
731723
732- #endif /* HAVE_FSTAT */
724+ #else
725+
726+ static PyObject *
727+ fileio_readall (fileio * self )
728+ {
729+ _Py_IDENTIFIER (readall );
730+ return _PyObject_CallMethodId ((PyObject * )& PyRawIOBase_Type ,
731+ & PyId_readall , "O" , self );
732+ }
733+
734+ #endif /* HAVE_FSTAT || MS_WINDOWS */
733735
734736static PyObject *
735737fileio_read (fileio * self , PyObject * args )
0 commit comments