| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 18d1924 commit f2f373f
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,11 +21,40 @@ PyAPI_FUNC(int) _Py_wstat( | |||
| 21 | 21 | struct stat *buf); | |
| 22 | 22 | #endif | |
| 23 | 23 | ||
| 24 | + #if defined(HAVE_FSTAT) || defined(MS_WINDOWS) | ||
| 25 | + | ||
| 26 | + #ifdef MS_WINDOWS | ||
| 27 | + struct _Py_stat_struct { | ||
| 28 | + unsigned long st_dev; | ||
| 29 | + __int64 st_ino; | ||
| 30 | + unsigned short st_mode; | ||
| 31 | + int st_nlink; | ||
| 32 | + int st_uid; | ||
| 33 | + int st_gid; | ||
| 34 | + unsigned long st_rdev; | ||
| 35 | + __int64 st_size; | ||
| 36 | + time_t st_atime; | ||
| 37 | + int st_atime_nsec; | ||
| 38 | + time_t st_mtime; | ||
| 39 | + int st_mtime_nsec; | ||
| 40 | + time_t st_ctime; | ||
| 41 | + int st_ctime_nsec; | ||
| 42 | + unsigned long st_file_attributes; | ||
| 43 | + }; | ||
| 44 | + #else | ||
| 45 | + # define _Py_stat_struct stat | ||
| 46 | + #endif | ||
| 47 | + | ||
| 48 | + PyAPI_FUNC(int) _Py_fstat( | ||
| 49 | + int fd, | ||
| 50 | + struct _Py_stat_struct *stat); | ||
| 51 | + #endif /* HAVE_FSTAT || MS_WINDOWS */ | ||
| 52 | + | ||
| 24 | 53 | #ifdef HAVE_STAT | |
| 25 | 54 | PyAPI_FUNC(int) _Py_stat( | |
| 26 | 55 | PyObject *path, | |
| 27 | 56 | struct stat *statbuf); | |
| 28 | - #endif | ||
| 57 | + #endif /* HAVE_STAT */ | ||
| 29 | 58 | ||
| 30 | 59 | #ifndef Py_LIMITED_API | |
| 31 | 60 | PyAPI_FUNC(int) _Py_open( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -752,9 +752,8 @@ Py_Main(int argc, wchar_t **argv) | |||
| 752 | 752 | } | |
| 753 | 753 | } | |
| 754 | 754 | { | |
| 755 | - /* XXX: does this work on Win/Win64? (see posix_fstat) */ | ||
| 756 | - struct stat sb; | ||
| 757 | - if (fstat(fileno(fp), &sb) == 0 && | ||
| 755 | + struct _Py_stat_struct sb; | ||
| 756 | + if (_Py_fstat(fileno(fp), &sb) == 0 && | ||
| 758 | 757 | S_ISDIR(sb.st_mode)) { | |
| 759 | 758 | fprintf(stderr, "%ls: '%ls' is a directory, cannot continue\n", argv[0], filename); | |
| 760 | 759 | fclose(fp); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -459,8 +459,8 @@ mmap_size_method(mmap_object *self, | |||
| 459 | 459 | ||
| 460 | 460 | #ifdef UNIX | |
| 461 | 461 | { | |
| 462 | - struct stat buf; | ||
| 463 | - if (-1 == fstat(self->fd, &buf)) { | ||
| 462 | + struct _Py_stat_struct buf; | ||
| 463 | + if (-1 == _Py_fstat(self->fd, &buf)) { | ||
| 464 | 464 | PyErr_SetFromErrno(PyExc_OSError); | |
| 465 | 465 | return NULL; | |
| 466 | 466 | } | |
@@ -1107,7 +1107,7 @@ static PyObject * | |||
| 1107 | 1107 | new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) | |
| 1108 | 1108 | { | |
| 1109 | 1109 | #ifdef HAVE_FSTAT | |
| 1110 | - struct stat st; | ||
| 1110 | + struct _Py_stat_struct st; | ||
| 1111 | 1111 | #endif | |
| 1112 | 1112 | mmap_object *m_obj; | |
| 1113 | 1113 | PyObject *map_size_obj = NULL; | |
@@ -1174,7 +1174,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) | |||
| 1174 | 1174 | (void)fcntl(fd, F_FULLFSYNC); | |
| 1175 | 1175 | #endif | |
| 1176 | 1176 | #ifdef HAVE_FSTAT | |
| 1177 | - if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) { | ||
| 1177 | + if (fd != -1 && _Py_fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) { | ||
| 1178 | 1178 | if (map_size == 0) { | |
| 1179 | 1179 | if (st.st_size == 0) { | |
| 1180 | 1180 | PyErr_SetString(PyExc_ValueError, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments