@@ -180,9 +180,9 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
180
180
static int
181
181
check_fd (int fd )
182
182
{
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 )) {
186
186
PyObject * exc ;
187
187
char * msg = strerror (EBADF );
188
188
exc = PyObject_CallFunction (PyExc_OSError , "(is)" ,
@@ -222,8 +222,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
222
222
#elif !defined(MS_WINDOWS )
223
223
int * atomic_flag_works = NULL ;
224
224
#endif
225
- #ifdef HAVE_FSTAT
226
- struct stat fdfstat ;
225
+ #if defined( HAVE_FSTAT ) || defined( MS_WINDOWS )
226
+ struct _Py_stat_struct fdfstat ;
227
227
#endif
228
228
int async_err = 0 ;
229
229
@@ -420,9 +420,11 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
420
420
}
421
421
422
422
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 );
425
426
goto error ;
427
+ }
426
428
#if defined(S_ISDIR ) && defined(EISDIR )
427
429
/* On Unix, open will succeed for directories.
428
430
In Python, there should be no file objects referring to
@@ -437,7 +439,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
437
439
if (fdfstat .st_blksize > 1 )
438
440
self -> blksize = fdfstat .st_blksize ;
439
441
#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
440
- #endif /* HAVE_FSTAT */
442
+ #endif /* HAVE_FSTAT || MS_WINDOWS */
441
443
442
444
#if defined(MS_WINDOWS ) || defined(__CYGWIN__ )
443
445
/* don't translate newlines (\r\n <=> \n) */
@@ -603,17 +605,7 @@ fileio_readinto(fileio *self, PyObject *args)
603
605
return PyLong_FromSsize_t (n );
604
606
}
605
607
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 )
617
609
618
610
static size_t
619
611
new_buffersize (fileio * self , size_t currentsize )
@@ -637,7 +629,7 @@ new_buffersize(fileio *self, size_t currentsize)
637
629
static PyObject *
638
630
fileio_readall (fileio * self )
639
631
{
640
- struct stat st ;
632
+ struct _Py_stat_struct st ;
641
633
Py_off_t pos , end ;
642
634
PyObject * result ;
643
635
Py_ssize_t bytes_read = 0 ;
@@ -655,7 +647,7 @@ fileio_readall(fileio *self)
655
647
#else
656
648
pos = lseek (self -> fd , 0L , SEEK_CUR );
657
649
#endif
658
- if (fstat (self -> fd , & st ) == 0 )
650
+ if (_Py_fstat (self -> fd , & st ) == 0 )
659
651
end = st .st_size ;
660
652
else
661
653
end = (Py_off_t )- 1 ;
@@ -729,7 +721,17 @@ fileio_readall(fileio *self)
729
721
return result ;
730
722
}
731
723
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 */
733
735
734
736
static PyObject *
735
737
fileio_read (fileio * self , PyObject * args )
0 commit comments