| 1027 | } |
| 1028 | |
| 1029 | bool Input::file_ready() |
| 1030 | { |
| 1031 | if (file_ == NULL || feof(file_)) |
| 1032 | return false; |
| 1033 | #if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(__BORLANDC__)) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) |
| 1034 | return !ferror(file_); |
| 1035 | #else |
| 1036 | int fd = fileno(file_); |
| 1037 | if (ferror(file_)) |
| 1038 | { |
| 1039 | if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) |
| 1040 | return false; |
| 1041 | #if defined(__linux__) |
| 1042 | // Linux has regular files that can be set non-blocking to raise EAGAIN e.g. /proc and /sys |
| 1043 | if (errno == EAGAIN) |
| 1044 | { |
| 1045 | struct stat buf; |
| 1046 | if (fstat(fd, &buf) == 0 && S_ISREG(buf.st_mode)) |
| 1047 | return false; |
| 1048 | } |
| 1049 | #endif |
| 1050 | } |
| 1051 | while (true) |
| 1052 | { |
| 1053 | struct timeval tv; |
| 1054 | fd_set rfds, efds; |
| 1055 | FD_ZERO(&rfds); |
| 1056 | FD_ZERO(&efds); |
| 1057 | FD_SET(fd, &rfds); |
| 1058 | FD_SET(fd, &efds); |
| 1059 | tv.tv_sec = 0; |
| 1060 | tv.tv_usec = 10000; // 10ms timeout |
| 1061 | clearerr(file_); // unset EAGAIN etc |
| 1062 | if (::select(fd + 1, &rfds, NULL, &efds, &tv) >= 0) |
| 1063 | return FD_ISSET(fd, &efds) == 0; |
| 1064 | if (errno != EINTR) |
| 1065 | return false; |
| 1066 | } |
| 1067 | #endif |
| 1068 | } |
| 1069 | |
| 1070 | void Input::wstring_size() |
| 1071 | { |
nothing calls this directly
no outgoing calls
no test coverage detected